- 安装命令 mysqldump
sudo apt update
sudo apt install mysql-client
- 编辑脚本内容 export_mysql.sh
#!/bin/bash
container_ip="172.26.77.246"
mysql_user="root"
mysql_password="your_password"
databases=("website1" "website2" "website3")
export_dir="/path/to/export/directory"
mkdir -p $export_dir
for db_name in "${databases[@]}"
do
export_file="$export_dir/$db_name.sql"
mysqldump -h $container_ip -u $mysql_user -p$mysql_password $db_name > $export_file
echo "数据库 $db_name 已导出到 $export_file"
done
tar -cvzf $export_dir/archive_$(date +%Y%m%d).tar.gz $export_dir/*.sql
rm -rf $export_dir/*.sql
- 执行以下命令给脚本添加执行权限:
chmod +x export_mysql.sh