Daily automatic backup of one-click LNMP installation package

Source: Internet
Author: User
When the server is running, problems will inevitably occur, such as the service provider's path and the hard disk of the master server being damaged. As a webmaster, backing up data is indispensable. manual backup is indeed cumbersome. using a script, you can achieve the goal of backing up data on a daily basis. Here, we use the & ldquo; LNMP one-key installation package & rdquo; as an example. we need to prepare an FTP and a mailbox that can receive large attachments. 1. install the LNMP one-key installation package and prepare an FTP space

When the server is running, problems will inevitably occur, such as the service provider's path and the hard disk of the master server being damaged. As a webmaster, backing up data is indispensable. manual backup is indeed cumbersome. using a script, you can achieve the goal of backing up data on a daily basis.

 

Here, we take the "LNMP one-key installation package" as an example. we need to prepare an FTP address and a mailbox that can receive large attachments.


1. install LNMP one-key installation package and prepare an FTP space

If the preceding one-click package is not used, you must manually modify the settings in the following path.

We recommend that you use Godaddy for free 10 GB for FTP space. if you have BuyVM VPS, you can use a free BuyVM 5 GB backup space or another service provider's FTP space, select a file based on your actual needs, provided that the file can be connected and uploaded and deleted.


II. obtain the automatic backup script
1. install the email sending dependency component (optional)
yum install sendmail mutt

Run the preceding commands in SSH to install the Mail sending dependency component. if this component is not used, do not install it. We recommend that you do not install it.


2. obtain the backup script
wget http://soft.kwx.gd/tools/AutoBackupToFtp.sh

We strongly recommend that you download the backup script to your local machine, use DreamWeaver or EditPlus for editing, and upload it to the root directory.


3. Custom settings
1. open AutoBackupToFtp. sh

If you see the following text, follow the instructions in yellow and modify the text according to the actual situation.


#! /Bin/bash # where you want to modify from here MYSQL_USER = root # mysql username MYSQL_PASS = 123456 # mysql password MAIL_TO = cat@hostloc.com # Database sent to the mailbox FTP_USER = cat # ftp username FTP_PASS = 123456 # ftp password FTP_IP = imcat. in # ftp address FTP_backup = backup # directory for storing backup files on ftp, this requires the WEB_DATA =/home/www created on the ftp. # The website data to be backed up # The modification ends from here.

2. demonstrate how to set an LNMP one-click installation package
1) create a local backup file directory
Cd/homemkdir backup # Create a folder (the backup file is stored locally in/home/backup for three days)

2) modify AutoBackupToFtp. sh information
#! /Bin/bash # where you want to modify from here MYSQL_USER = root # mysql username MYSQL_PASS = 123456 # mysql password MAIL_TO = cat@hostloc.com # Database sent to the mailbox FTP_USER = cat # ftp username FTP_PASS = 123456 # ftp password FTP_IP = imcat. in # ftp address FTP_backup = backup # directory for storing backup files on ftp, you need to create WEB_DATA =/home/wwwroot on The ftp. # The website data to be backed up # the location where you want to modify the data should end here.

The red part must be modified. The remaining yellow description and corresponding parts must be modified according to the actual situation.

Email sending problems:

Search for files


# Send the database to Email. if the database size is too large after compression, comment out this line of echo "Topic: database backup" | mutt-a/home/backup/$ DataBakName-s ...... If not, add "#" before the following statements. Note the red part. # Echo "Topic: database backup" | mutt-a/home/backup/$ DataBakName-s ......

3. test whether the backup is normal.
sh /root/AutoBackupToFtp.sh

Do not close SSH during the test until the execution is complete. If no problem exists, continue.


4. scheduled execution and daily backup
1. Grant the file execution permission (755)
chmod +x /root/AutoBackupToFtp.sh

2. set automatic tasks
crontab -e

Run the preceding commands by using SSH.


3. add a task
1) add execution statement
00 00 * * * /root/AutoBackupToFtp.sh

Press the keyboard character "I" and press enter to start another line and add the above code. modify the path and time according to the actual situation.

Here, 00 is the time minute/hour and can be modified by yourself. for example: 30 00 ***, this script is run at every day.


2) save and exit

Press the "Esc" key on the keyboard, exit the editing mode, press shift +; (I .e., ":"), enter wq, press enter, save and exit to take effect.

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.