How to implement VPS Free backup script under linux
Today, I would like to share with you the relevant knowledge of how to achieve VPS free backup script under linux. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article.
The code is as follows:
#! / bin/bash
# set-x
Time= `date +% y% m% d`
# here is the backup mysql
[!-e / backup/sqltmp] & & mkdir-p / backup/sqltmp # create a temporary backup mysql directory
[!-e / backup/backsql] & & mkdir-p / backup/backsql # create a directory where mysql backups are stored
Cd / backup/sqltmp
Sql= `mysqlshow-u username-p password | grep-v + | grep-ev "data | information | mysql | test" | awk {'print $2'} `# query website databases other than system data in mysql database. You can modify them here as needed.
For sqlname in $sql
Do
Mysqldump-u username-p password $sqlname > $sqlname.sql
Done
Tar zcvf backsql.$time.tar.gz * .sql
Rm-rf * .sql
Mv *.. / backsql/.
Cd..
Rm-rf sqltmp
# here is the backup website
[!-e / backup/webtmp] & & mkdir-p / backup/webtmp # create a temporary backup web file directory
[!-e / backup/backweb] & & mkdir-p / backup/backweb # create a directory where web file backups are stored
Cd / backup/webtmp
Tar zcvf backweb.$time.tar.gz / home/*
Mv *.. / backweb/.
Cd..
Rm-rf webtmp
The following is a script for uploading a backup site to the godaddy space via ftp:
The copy code is as follows:
#! / bin/bash
Backsql= `CD / backup/backsql;ls-r backsql* | head-1` # because the latest file is backed up every day
Backweb= `CD / backup/backweb;ls-r backweb* | head-1`
Ftp-n