Mysql数据库备份脚本


#!/bin/bash # description: This Is Backup-Script for Mysql #By WangXiaoKe #DATE 2016,6,1 #定义脚本变量 TIME=$(date +%Y%m%d) # 删除30天以前的备份文件 /usr/bin/find /backup-script/ -name '*.tar' -mtime +30 -exec rm -rf {} \; # 备份bdfwpt数据库 /usr/bin/mysqldump -u root -p123456 bdfwpt --default-character-set="utf8" --add-drop-database --add-drop-table > /backup-script/bdfwpt${TIME}.sql # 打包备份数据 cd /backup-script/ /bin/tar -cvf ${TIME}.tar bdfwpt${TIME}.sql&&rm -rf *.sql # 判断是否备份成功并写入文件记录 if [ $? -eq 0 ];then echo ${TIME}备份数据库成功 >> /backup-script/backuplog else echo ${TIME}备份数据库失败 >> /backup-script/backuplog fi ########################################################## 拷贝到FTP服务器############################################# /usr/bin/ftp -n<<! open 10.8.252.251 prompt user bdw bdw lcd /backup-script/ cd databases put backuplog mkdir ${TIME} cd ${TIME} mput ${TIME}.tar close bye !
posted @ 2017-02-03 18:52  一王小可一  阅读(252)  评论(0编辑  收藏  举报