#!/bin/sh
d=`date +%y%m01`
l=`date -d "$1 months ago $d last day" +%Y-%m-%d`
f=`date -d "$l" +%Y-%m-01`
y=`date -d "$l" +%Y`
`/data/mysql/bin/mysql -uuser -ppassword -e "select * into outfile '/data/backup/score_$l' FROM score.score_actions_$y where action_code ='666' and action_date>'$f 00:00:00' and action_date<'$l 23:59:59';"`
lftp -c "open 192.168.172.73;use user password;cd scoretest;put /data/backup/score_$l"
d=`date +%y%m01`
l=`date -d "$1 months ago $d last day" +%Y-%m-%d`
f=`date -d "$l" +%Y-%m-01`
y=`date -d "$l" +%Y`
`/data/mysql/bin/mysql -uuser -ppassword -e "select * into outfile '/data/backup/score_$l' FROM score.score_actions_$y where action_code ='666' and action_date>'$f 00:00:00' and action_date<'$l 23:59:59';"`
lftp -c "open 192.168.172.73;use user password;cd scoretest;put /data/backup/score_$l"

本文介绍了一个使用Shell脚本来备份MySQL数据库的具体实现方法。该脚本通过参数指定时间范围来选择要备份的数据,并将其导出到指定路径,之后通过lftp命令将备份文件上传到远程服务器。
3702

被折叠的 条评论
为什么被折叠?



