Chinaunix首页 | 论坛 | 博客
  • 博客访问: 709692
  • 博文数量: 139
  • 博客积分: 7607
  • 博客等级: 少将
  • 技术积分: 1964
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-11 23:43
个人简介

...

文章分类

全部博文(139)

文章存档

2012年(53)

2011年(4)

2010年(29)

2009年(10)

2008年(33)

2007年(10)

分类: LINUX

2012-02-15 16:02:50

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

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