分类:
2012-03-26 22:38:46
原文地址:最实用的Shell脚本自动备份网站及数据库 作者:jerryswxs
简单的shell脚本,自动备份网站及数据库,并异地备份到其他服务器!最实用的Shell脚本自动备份网站及数据库。
#!/bin/sh
###脚本目的:自动备份mysql和www
###编写时间:2011年3月10日8:33:37
###定义变量###
backpath=/data/backup/`date +%Y%m%d`
ftpserver=192.168.0.23
ftppath=chinaapp.sinaapp.com
ftpuser=wugk
ftppwd=111qqq,,,
sqlpath=/usr/local/mysql
sqluser=root
sqlpwd=chinaapp.sinaapp.com
sqldb=wgkgood
echo “##########定义变量完成,请等待…………………….”
cat << EOF
++++++++++++++ Welcome To Auto Backup Mysql Shell Center +++++++++++++++++++++++++++
++++++++++++ +++++++++++++++++++++++++++
++++++++++++++ Please Wait a Few Minutes ,Shell Now is Start +++++++++++++++++++++++++++
EOF
sleep 3s
if
[ $UID -ne 0 ];then
echo "This script must use administrator or root user ,please exit ......."
exit 0
fi
sleep 2s
if
[ ! -d $backpath ];then
mkdir -p $backpath
else
echo "This DIR is Exist ,do not again mkdir ..............."
fi
echo "NOW Time is `date +%Y-%m-%d-%M:%H:%S`"
cd $backpath && $sqlpath/bin/mysqldump -u$sqluser -p$sqlpwd $sqldb >$sqldb-`date +%Y%m%d`.sql
find . -name “*`date +%Y%m%d`.sql” |xargs tar czf `date +%Y%m%d`-$sqldb.tar.gz |xargs rm -rf *.sql
cd /home/webapps/ && tar czf `date +%Y%m%d`- www &&mv -f *.gz $backpath
cd /usr/local && tar czf `date +%Y%m%d`-php+nginx.tar.gz nginx php &&mv -f *.gz $backpath
find /data/backup/ -mtime +5 -type d |xargs rm -rf {}\;
echo “++++++++++++Mysql And Www Backup is Finished, Please wait for backup to the FTP ++++++++++++++++++++++++++++++++++”
ftp -i -n << end_ftp
open $ftpserver
user $ftpuser $ftppwd
binary
lcd $backpath
mkdir $ftppath
cd $ftppath
prompt
mput *.gz
bye
close