标签:mtime date mysq mysqldump 产生 成功 %s 备份mysql bak
需求:备份mysql数据库并将数据备份的文件上传到ftp所在服务器1、root用户创建备份脚本路径:
$ mkdir /opt/databak
$ cd /opt/databak
2、创建备份脚本:
#vi /opt/databak/dbbak.sh
#!/bin/sh
timedate=$(date +%Y%m%d%H%M%S)
dbname=root
dbpasswd=1334
babydbname=bwang
babydbhome=/opt/databak
mysqldump -u$dbname -p$dbpasswd $babydbname >$babydbhome/$babydbname-$timedate.sql
sleep 5
find $babydbhome/*.sql -mtime +30 -exec rm -rf {} \;
cd $babydbhome
ftp -v -n 192.168.6.9 >>$babydbname-$timedate.log << EOF #将上传过程中产生的打印信息写到$babydbname-$timedate.log里面,后面判断是否成功要用
user test test123
binary
hash
put $babydbname-$timedate.sql $babydbname-$timedate.sql
bye
EOF
给dbbak.sh脚本执行权限,做计划任务即可20 0 * * * /bin/sh /opt/databak/dbbak.sh
标签:mtime date mysq mysqldump 产生 成功 %s 备份mysql bak
原文地址:http://blog.51cto.com/meiling/2136014