备份数据库

以下为databak.sh备份脚本

#! /bin/bash
echo `date` ": 开始备份数据........" >>bak.log
#bakdate =`date "+%y%m%d"`
echo $bakdate
y=`date --date='1 days ago' "+%Y"`
m=`date --date='1 days ago' "+%m"`
d=`date --date='1 days ago' "+%d"`
bak_file="/home/ocss/data_bak/"$y"-"$m"-"$d".sql"
#bak_upfile="/home/ocss/data_bak/upfile"$y""$m""$d".tar.gz"
#bak_file="/home/ocss/data_bak/"$bakdate".sql"
mysqldump --opt -u root --password= ocss > $bak_file
tar -zcvf "$bak_file".gz $bak_file
#tar -N ""$y"/"$m"/"$d"" -zcvf $bak_upfile /home/ocss/tomcat5.5/webapps/ocss/upfile
echo "数据库已经成功备份到:" $bak_file >>bak.log
echo "开始发送到sftp://202.102.112.23" >> bak.log
lftp -u root,jiang-su-2008-hongxin sftp://202.102.112.23 <<EOF
cd /home/ocssbak
put "$bak_file".gz
#put $bak_upfile
bye
EOF
rm -rf $bak_file
#rm -rf $bak_upfile
echo "数据已经成功发送到sftp://202.102.112.23" >> bak.log
echo `date`+": 备份成功结束!" >> bak.log
echo "-------------------------------------------" >> bak.log

你可能感兴趣的:(数据库)