Linux VPS Host scheduled automatic backup site and MySQL database script

Source: Internet
Author: User
Tags prepare vps sublime editor
Since we started learning to build stations, whether we are using a free virtual host, or scraping the pay of the purchase of the host, and our larger projects need to turn to VPS or server storage; whether we are technical trained or old left, See netizens have their own site so enthusiastic also set up a play; whether our site is large or small, there is profit or no profit, we must learn basic self maintenance, especially the site data backup.

We do not rely too much on and trust the host to provide us with the backup, even if we buy the very cattle, very expensive service providers of products, they may be due to various possibilities caused by data loss or crash, we can choose to manually back up or use a certain technology to automatically back up, The former for the small amount of data on the personal site, the latter for the project more often want to automatically manage the site can implement automatic backup.

In the old left blog, there have been a lot of Web sites, VPS backup articles, some simple manual backup files and database export, some more high-end synchronous incremental backup, for our users, choose a suitable for their own, after all, we just need to learn to use and the results can be achieved.

The code is as follows Copy Code

1, configure Rsync to implement a timed synchronous mirror VPS Site Backup replacement Incremental backup files

2, Linux VPS Auto Sync backup files/database to copy storage site

3, free use of multiple backup scheduled online backup Web site files and databases

Because the last time the old left in the play before the purchase of GoDaddy economic host, there is no need to build a station, but can be used to back up our VPS in the site storage use, the individual believes that the backup to their own host files than relying on Third-party backup storage security A lot, do you think?

In many online automatic backup script, old left that the automatic backup of the elder brother's FTP upload script is still relatively good, you can automatically package the database and Web page files, and then regularly uploaded to the designated FTP host. So, in this article, explain the actual use of this script.

First, preparatory work

We need to prepare an FTP host, make sure you can use the FTP tool link open, pay attention to the password do not get wrong. For example, this host in my hand is connected with FTP after this.

We first confirm that the FTP Host account is correct, and need to get a backup directory, where we need httpdocs, not every host is the same, we have to back up to this directory, or in the folder can be inside. (some may be wwwroot)

Second, we need to install the VPS environment Lftp, for uploading file application use.

The code is as follows Copy Code

Yum-y Install Lftp

For example, in the CentOS environment to perform the above Yum script run installation, if it is Debian modified to Apt-get

Again, we need to create a folder in the VPS environment for backing up file storage, such as in/www/backup. The principle is that after the execution of the script, our website and database are backed up into the/www/backup and then uploaded to the FTP space using the script lftp.

Second, edit the backup script

The code is as follows Copy Code

http://soft.laozuo.org/backup/backup.sh

In the script above, we need to download to the local, and then edit (not with Notepad), with EditPlus or sublime editor. This needs to be explained in a separate way, because it is very easy for beginners to make mistakes when it comes to our VPS paths and actual configurations.

We start from above, must pay attention to modify the configuration, Backup_dir on behalf of our current site in the VPS folder path, according to the actual situation modification. Here is a backup of 2 sites, if we only need to back up a site, then remove one line, note the following parameters 1, 2, as well as multiple Web sites one analogy.

MySQL database information, the middle part of the need to write the root information of the MySQL account, so as to ensure that the full backup, the following is written on the need to back up the site's database name, if only a backup, we remove a row, if multiple, add more lines, pay attention to parameters.

Here is also more critical, we need to fill in the preparation of the time to prepare the FTP account, especially ftp_backupdir we need to correspond to the direct FTP tool to see the file storage directory, according to the actual situation is not the same as each host.

Here we need to pay attention to 2 questions, one is if we just back up a site, that the extra line to be removed, because the default old left is written 2 to distinguish, if there are multiple sites when the backup directory. And we need to pay attention to the directory problem, in this script, my directory in the WWW, some in the home, some in Var, different, we need to according to their actual situation, and then modify their own path. (check carefully)

Third, deploy a test backup

After we have no problem with the modifications, we upload them to the root directory in the VPS. We can test if it is possible to back up.

The code is as follows Copy Code

sh/root/backup.sh

We can see that after performing the test backup, we perform the compression and upload process.

Four, deploy automatic scheduled backup

We add the script to the crontab to implement a scheduled backup, such as we set up 1 o'clock in the morning every day.

The code is as follows Copy Code

Crontab-e

Open the Crontab file, and then add

The code is as follows Copy Code

0 1 * * */root/backup.sh

Can be a daily scheduled backup, if we do not need to do so frequently, you can modify the timing of time, such as a weekly time backup execution. The premise is that we need to have the crontab installed. Look at the backup data that I tested here.

In the old left FTP space, you can see three days of backup data, databases and files are packaged separately, if necessary can be downloaded to the local.

Summary, if our site is small or not very busy, can be manually backed up, the setup of automatic backup we can first test the machine test, and then deploy, although this FTP backup script is relatively simple, but still need to test the perfect after deployment, we see any tutorials, even if the old left Test released, But when we use it ourselves, we need to test to make sure it's okay.
Related Article

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.