Chinaunix首页 | 论坛 | 博客
  • 博客访问: 214326
  • 博文数量: 87
  • 博客积分: 192
  • 博客等级: 入伍新兵
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-14 07:44
文章分类

全部博文(87)

文章存档

2013年(1)

2012年(86)

分类:

2012-03-26 22:38:46

简单的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

阅读(672) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~