#/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
File was successfully backed up: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/56/wKiom1RPrLegsJB1AAOgZMO02CM727.jpg "title = "2014-10-28 22:47:52 screen. png" alt= "wkiom1rprlegsjb1aaogzmo02cm727.jpg"/>
Automatic backup every night 4 o'clock in the morning:
[Email protected] opt]# crontab-l
0 4 * * * bash/opt/echo.sh
This article is from the "Dragon Love Xue qi" blog, please make sure to keep this source http://dragon123.blog.51cto.com/9152073/1569011
Using the shell to back up sites and databases