Linux automatically timed backup Linux vps/Server Web site files and databases and FTP upload to host space

Source: Internet
Author: User
Tags vps
First, install LFTP environment

Because we need to use the LFTP environment when uploading FTP files, we can't make sure all the systems are installed, so we'd better reinstall them first.

The code is as follows Copy Code

#CentOS Yum Install lftp

#Debian Apt-get Install Lftp

Second, create a backup directory

The code is as follows Copy Code

/home/backup/

We need to create a backup directory in the VPS, because in the execution of the backup, it is necessary to back up to the VPS local, and then upload from the local to the remote FTP space. We need to match this address with the following script.

Third, prepare the automatic backup script

The code is as follows Copy Code

http://soft.itbulu.com/tools/backup.sh

We can download the above script to the local/vps and then modify the configuration. The main setting parameters are explained below by Chiang Kai-shek.

The code is as follows Copy Code

######~ set up a Site Directory folder to be backed up ~######
Backup_dir1=itbulu.com
Backup_dir2=laojiang.me
Backup_dir3=shimaisui.com
Backup_dir4=website4.com

######~ Set up Database links ~######
Mysql_username=root
Mysql_password=yourrootpassword

######~ set the database name to be backed up ~######
Backup_database_name1=itbulu
Backup_database_name2=laojiang
Backup_database_name3=shimaisui
Backup_database_name4=website4

######~ uploaded FTP space information ~######
ftp_hostname=198.38.34.12
Ftp_username=itbulucom
Ftp_password=yourftppassword
Ftp_backupdir=backup//Backup to FTP directory, this need to build a directory ahead of time

#Values Setting end!

All we have to do is modify the backup.sh file above to make the site and database link information that we need to back up.

Upload the script to the root directory.

Set script permissions and scheduled backups

We upload to the VPS host root directory, and then set permissions

The code is as follows Copy Code

chmod +x/root/backup.sh

Open CRONTAB-E

The code is as follows Copy Code

0 3 * * */root/backup.sh

Add the timed script above to perform a backup every 3 o'clock in the morning. We can first execute the script to see if it will work properly, if it can be set regularly. If our site data is not large, update frequency is not too much, we manually backup can also, there is no need to back up every day.

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.