Linux to achieve free backup of the VPS script _linux

Source: Internet
Author: User
Tags mkdir vps
Someone said why don't you back up? This question I also considered ah, in fact, you have not thought about such a foreign VPS what, back up all the site how to say also have to Baixin trillion it.

You can't download it every day? This bandwidth can not stand, even if the bandwidth is sufficient, perhaps the VPS will also let you download the day to hang.

Ok~ cut to the point, the first to say that this free backup problem, in fact, can not be cost, but there is a prerequisite, That's the name you bought in GoDaddy.com. We all know in GoDaddy to buy a domain name can be free to apply for space, for this thing is really too wasteful, so today's theme is for those who bought a domain name in GoDaddy have free space in the Basin friends (in the GoDaddy has domain name does not apply for space can Ask the Google of the mother.

Then we back up the VPS principle is to use Shell script backup site and database, and then through the FTP script backup files uploaded to GoDaddy free space, simple.

Then I will directly on the script ~ hehe.

The following is a script to back up the Web site and database:
Copy Code code as follows:

#!/bin/bash
#set-X
Time= ' Date +%y%m%d '
#下面是备份MySql
[!-e/backup/sqltmp] && mkdir-p/backup/sqltmp #创建临时备份mysql目录
[!-e/backup/backsql] && mkdir-p/backup/backsql #创建mysql备份的存放目录
Cd/backup/sqltmp
Sql= ' mysqlshow-u username-p password |grep-v + | Grep-ev "Data|information|mysql|test" | awk {' Print $2′} ' #查询mysql数据库里出系统数据以外的网站数据库, which can be modified to suit your needs
For Sqlname in $sql
Todo
Mysqldump-u User name-p password $sqlname > $sqlname. sql
Done
Tar zcvf backsql. $time. tar.gz *.sql
RM-RF *.sql
MV *.. /backsql/.
Cd..
RM-RF sqltmp
#下面是备份网站
[!-e/backup/webtmp] && mkdir-p/backup/webtmp #创建临时备份web文件目录
[!-e/backup/backweb] && mkdir-p/backup/backweb #创建web文件备份的存放目录
Cd/backup/webtmp
Tar zcvf backweb. $time. tar.gz/home/*
MV *.. /backweb/.
Cd..
RM-RF webtmp

The following is uploaded via FTP to the backup site uploaded to GoDaddy space on the script:
Copy Code code as follows:

#!/bin/bash
Backsql= ' Cd/backup/backsql;ls-r backsql* | Head-1 ' #因为每天都备份文件取最新的那个
backweb= ' Cd/backup/backweb;ls-r backweb* | Head-1 '
Ftp-n<<eof
Open IP #这里写godaddy空间的ip
User FTP username FTP password
Binary
cd/back/#备份文件要存放的ftp上的路径
lcd/backup/backsql/#备份mysql文件本地存放路径
Prompt
Mput $backsql
lcd/backup/backweb/#备份web文件本地存放路径
Mput $backweb
Close
Bye
Eof

Then the two scripts to do a crontab planning task to achieve a regular off-site backup every day, and save time and energy saving.
Copy Code code as follows:

[Root@90itt.com ~]# Crontab-e
0 * * */root/backup.sh
0 5 * * */root/ftp.sh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.