码迷,mamicode.com
首页 > 数据库 > 详细

使用shell备份网站和数据库

时间:2014-10-29 02:05:42      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:shell

#/bin/bash

BackuPath=/opt/backup/

WebPath=/usr/local/apache2/htdocs/

DATE=`date +%Y%m%d`

WebBakFIle=web${DATE}.tar.bz2

DBFile=DB${DATE}.tar.bz2

DBuser=‘root‘

DBpassword=‘123‘

FTPserver=192.168.1.107

FtpTargetPath=‘ftp/backup‘


cd $WebPath

pwd


tar jcf $WebBakFIle * | mv $WebBakFIle $BackuPath

for db in ` mysql -u$DBuser -p$DBpassword -B -N -e ‘show databases;‘ `

do

 mysqldump -u$DBuser -p$DBpassword --single-transaction  $db > ${db}.sql


done

for sqlfile in `ls -l | grep ".sql" | awk ‘{print $8}‘`

do

tar jcf $DBFile $sqlfile | mv $DBFile $BackuPath

done


cd  $BackuPath

pwd

ftp -v -n $FTPserver << END

user lbx qwe123

bin

cd $FtpTargetPath

ls -l

put $DBFile

put $WebBakFIle

bye

END



文件被成功备份:bubuko.com,布布扣



每晚凌晨4点自动备份:

[root@localhost opt]# crontab -l

0 4 * * * bash /opt/echo.sh


本文出自 “龙爱雪琪” 博客,请务必保留此出处http://dragon123.blog.51cto.com/9152073/1569011

使用shell备份网站和数据库

标签:shell

原文地址:http://dragon123.blog.51cto.com/9152073/1569011

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!