Home >Database >Mysql Tutorial >mysql 简单批量备份多个库_MySQL
bitsCN.com
#!/bin/bash
#This script is batch backup for mysql;
SQL_name='dbname1 dbname2 dbname3……dbnameN-1 dbnameN'
SQL_pwd='123456'
for i in $SQL_name
do
mysqldump -uroot -p$SQL_pwd $i > $i-$(date +%y-%m-%d-%H-%M)。sql
sleep 5
done
完整备份方案,将所有数据库备份后,进行打包压缩归档,同时删除原备份文件。
#!/bin/bash
SQL_name=''dbname1 dbname2 dbname3……dbnameN-1 dbnameN'' #数据库名称;
SQL_pwd='123456' #数据库密码;
SQL_path='/usr/local/mysql/bin' #数据库命令目录;
BACKUP_tmp=/data/backup/tmp #备份文件临时存放目录;
BACKUP_path=/data/backup #备份文件压缩打包存放目录;
for i in $SQL_name
do
$SQL_path/mysqldump -uroot -p$SQL_pwd $i > $BACKUP_tmp/$i-$(date +%y-%m-%d-%H-%M)。sql
sleep 3
done
sleep 60
#将备份数据打包,并删除原备份文件;
tar --remove-files -cvzf $BACKUP_path/school-backup-$(date +%y-%m-%d)。tar.gz $BACKUP_tmp/* 2&>1 /dev/null
exit 0
bitsCN.com