VPS free backup script in linux

Source: Internet
Author: User

Why don't you back up data? I have also considered this problem. Have you ever thought about such foreign vps or something? Back up all the websites and say that it would take hundreds of megabytes.

You cannot download it every day, right? This bandwidth is not enough. Even if the bandwidth is sufficient, you may have to download the vps one day.

OK ~ Let's get started with this free backup question. It's actually not free, but there is a premise that you have bought a domain name at godaddy.com, we all know that purchasing a domain name on godaddy can apply for free space. It is a waste of resources, so today's topic is for those who have purchased a domain name in godaddy and have free space (if you have a domain name in godaddy, you can ask du Niang Gu Ge)

The principle of backing up vps is to use shell scripts to back up websites and databases, and then upload backup files to godaddy free space through ftp scripts.

Then I will directly upload the script ~ Hey.

The following is a script for backing up websites and databases:Copy codeThe Code is as follows :#! /Bin/bash
# Set-x
Time = 'date + % Y % m % d'
# The following describes how to back up MySql
[! -E/backup/sqltmp] & mkdir-p/backup/sqltmp # create a temporary backup mysql directory
[! -E/backup/backsql] & mkdir-p/backup/backsql # create a directory for storing mysql backups
Cd/backup/sqltmp
SQL = 'mysqlshow-u username-p password | grep-v + | grep-Ev "Data | information | mysql | test" | awk {'print $2 '}' # Query A website database other than the system data in the mysql database, you can modify the parameters 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
# Below 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 for storing web file backup
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 website to a godaddy space through ftp:Copy codeThe Code is as follows :#! /Bin/bash
Backsql = 'CD/backup/backsql; ls-r backsql * | head-1' # The latest backup file
Backweb = 'CD/backup/backweb; ls-r backweb * | head-1'
Ftp-n <EOF
Open ip # Write the ip address of the godaddy space here
User ftp Username ftp Password
Binary
Cd/back/# path of the ftp to be stored in the backup file
LCD/backup/backsql/# local backup path for mysql files
Prompt
Mput $ backsql
LCD/backup/backweb/# local path for backing up web files
Mput $ backweb
Close
Bye
EOF

Then, the two scripts will be used as a crontab scheduled task to implement regular remote backup every day, saving time and effort.Copy codeThe Code is as follows: [root@90itt.com ~] # Crontab-e
01 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.