Implement VPS free backup scripts under linux
- 2020-05-06 12:01:57
- OfStack
Some people say why don't you back up? This problem I also considered ah, in fact, you have not thought of this kind of foreign vps what, backup all the website how to say also get 100 megabytes.
You can't download every day, can you? This bandwidth can not bear, even if the bandwidth is sufficient, perhaps vps one day also let you to download to hang.
ok ~ cut to the chase, said the first free backup problem, in fact also not free, but there is a premise, that is you in godaddy. com bought a domain name, as you all know on godaddy buy domain name can apply for free space, for without this thing is too waste, so today's topic is aimed at those friend in godaddy bought the domain name has free space (in godaddy haven't apply for a domain name space can ask baidu Google)
So the idea behind backing up vps is to back up websites and databases using shell scripts, and then upload the backup files to godaddy's free space via ftp scripts, simple.
Then I go straight to the script ~ hey hey.
Here's a script for backing up your website and database:
The following is a script for uploading the backup site to the godaddy space via ftp:
Then make an crontab schedule of these two scripts and you'll be able to backup them at the same time and in different locations every day, saving time, effort and money.
You can't download every day, can you? This bandwidth can not bear, even if the bandwidth is sufficient, perhaps vps one day also let you to download to hang.
ok ~ cut to the chase, said the first free backup problem, in fact also not free, but there is a premise, that is you in godaddy. com bought a domain name, as you all know on godaddy buy domain name can apply for free space, for without this thing is too waste, so today's topic is aimed at those friend in godaddy bought the domain name has free space (in godaddy haven't apply for a domain name space can ask baidu Google)
So the idea behind backing up vps is to back up websites and databases using shell scripts, and then upload the backup files to godaddy's free space via ftp scripts, simple.
Then I go straight to the script ~ hey hey.
Here's a script for backing up your website and database:
#!/bin/bash
#set -x
time=`date +%Y%m%d`
# Here's the backup MySql
[ ! -e /backup/sqltmp ] && mkdir -p /backup/sqltmp # Create a temporary backup mysql directory
[ ! -e /backup/backsql ] && mkdir -p /backup/backsql # create mysql Backup storage directory
cd /backup/sqltmp
sql=`mysqlshow -u The user name -p password |grep -v + | grep -Ev " Data|information|mysql|test " | awk { ' print $2 ' }` # The query mysql Database out of the system data site database , This can be changed as needed
for sqlname in $sql
do
mysqldump -u The user name -p password $sqlname > $sqlname.sql
done
tar zcvf backsql.$time.tar.gz *.sql
rm -rf *.sql
mv * ../backsql/.
cd ..
rm -rf sqltmp
# Below is the backup site
[ ! -e /backup/webtmp ] && mkdir -p /backup/webtmp # Create a temporary backup web File directory
[ ! -e /backup/backweb ] && mkdir -p /backup/backweb # create web File backup directory
cd /backup/webtmp
tar zcvf backweb.$time.tar.gz /home/*
mv * ../backweb/.
cd ..
rm -rf webtmp
The following is a script for uploading the backup site to the godaddy space via ftp:
#!/bin/bash
backsql=`cd /backup/backsql;ls -r backsql* | head -1` # Because every day you back up your files and get the latest one
backweb=`cd /backup/backweb;ls -r backweb* | head -1`
ftp -n<<EOF
open ip # Here to write godaddy Of the space ip
user ftp The user name ftp password
binary
cd /back/ # Backup files to store ftp On the path to the
lcd /backup/backsql/ # The backup mysql File local storage path
prompt
mput $backsql
lcd /backup/backweb/ # The backup web File local storage path
mput $backweb
close
bye
EOF
Then make an crontab schedule of these two scripts and you'll be able to backup them at the same time and in different locations every day, saving time, effort and money.
[root@90itt.com ~]# crontab -e
01 0 * * * /root/backup.sh
0 5 * * * /root/ftp.sh