时间:2021-07-01 10:21:17 帮助过:17人阅读
Remote-Server: 10.70.33.89
1,在db-server:
# mysql -uroot -p mysql> use mysql; Database changed
创建备份帐号:
mysql> GRANT SELECT,RELOAD,LOCK TABLES ON *.* TO ‘backupdb‘@‘localhost‘ identified by ‘12345678#qweD‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
创建备份脚本:
# cat backup_mydb.sh #!/bin/bash back_mydb(){ Date=`date -d "yesterday" +%Y-%m-%d` dbname=test1234 dbuser=backupdb dbpasswd=12345678#qweD /usr/bin/mysqldump -u$dbuser -p$dbpasswd --databases $dbname > /tmp/${dbname}_$Date.sql #如果数据库导出来很大,可压缩再发送到远端: gzip -c /tmp/${dbname}_$Date.sql > /tmp/${dbname}_$Date.sql.gz rsync -avz /tmp/${dbname}_$Date.sql.gz nobody@10.70.33.89::mydb_bak rm -f /tmp/${dbname}_$Date.sql* } back_mydb
添加计划任务:
# crontab -e # backup ‘test1234‘ DB by chongzi 2015.6.19 0 1 * * * /bin/bash /data1/scripts/backup_myDB.sh
2,远端服务器rsync配置:
[mydb_bak] path = /backup/mydb comment = Backup CMS MysqlDB for ‘test1234‘ ignore errors read only = no list = no hosts allow = 10.70.33.90
创建备份目录,并赋予相应权限:
# mkdir /backup/mydb # chown -R nobody.nobody /backup/mydb
本文出自 “daemonSA” 博客,请务必保留此出处http://daemonsa.blog.51cto.com/340243/1663589
将本地数据库备份到远程服务器
标签:mysql 备份