MySQL数据库备份脚本

实现功能:使用mysqldump备份指定数据库,使用tar就行压缩打包,再用openssl就行加密,最后将文件传输到备份服务器。

 

#!/bin/bash export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin cd /data/db_backup # db backup mysqldump -u'Username' -p'Password' --master-data=2 db1 > db1_`date +%Y-%m-%d`.sql mysqldump -u'Username' -p'Password' --master-data=2 db2 > db2_`date +%Y-%m-%d`.sql mysqldump -u'Username' -p'Password' --master-data=2 db3 > db3_`date +%Y-%m-%d`.sql tar zcf db_`date +%Y-%m-%d`.sql.tgz db1_`date +%Y-%m-%d`.sql db2_`date +%Y-%m-%d`.sql db3_`date +%Y-%m-%d`.sql rm -f db1_`date +%Y-%m-%d`.sql db2_`date +%Y-%m-%d`.sql db3_`date +%Y-%m-%d`.sql # encrypt openssl enc -des -e -in db_`date +%Y-%m-%d`.sql.tgz -out db_`date +%Y-%m-%d`.sql.tgz.sec -pass pass:yourPassword # ftp upload host="192.168.1.101" id="backup_user" pw='yourPassword' basedir="/data/db_backup" remotedir="./db" backupfile1=db_`date +%Y-%m-%d`.sql.tgz.sec ftp -n "$host" >> ${basedir}/ftp_log/ftp.log 2>&1 <<EOF user $id $pw binary prompt off passive off cd $remotedir put $backupfile1 bye EOF # copy files to local directory mv -f *.sql.tgz* ./local

你可能感兴趣的:(数据库,mysql,Date,加密,服务器,db2)