Lftp enables automatic local backup of websites and databases with FTP upload backup script

Source: Internet
Author: User
Preparations: lftp must be installed in VPS in advance. lftp is powerful. CentOS directly executes: yuminstalllftp and Debian execute: apt-getinstalllftp. You need to create the/home/backup/directory on VPS and the backup directory on FTP. If there are not many VPS databases, you can use Godaddy free space (10 GB space, 300

Preparations:

Lftp needs to be installed in VPS in advance. lftp is powerful and can be directly executed in CentOS:Yum install lftp, Debian execution:Apt-get install lftp.

You need to create the/home/backup/directory on VPS and the backup directory on FTP.

If there are not many databases on the VPS, you can use Godaddy free space (10 GB space, GB traffic), as long as you register a domain name, it will be free.

The following part of the backup script is commented out:
#! /Bin/bash
# Funciont: Backup website and mysql database
# Author: licess
# Website: http://lnmp.org
# IMPORTANT !!! Please Setting the following Values!

######~ Set Directory you want to backup ~ ###### Change the following directory to the directory you want to back up. generally, all directories under/home/wwwroot/are directly written to be backed up. You can add more: Backup_Dir5 = your directory, and the numbers following Backup_Dir increase sequentially. If there are less than four, you can directly delete unnecessary ones and modify the tar zcf section below.

Backup_Dir1 = vpser.net
Backup_Dir2 = lnmp.org
Backup_Dir3 = licess.org
Backup_Dir4 = jungehost.com

######~ Set MySQL UserName and password ~ ###### Set the MySQL User name and password, preferably root. other users may be unable to export some databases due to permission issues.
MYSQL_UserName = root
MYSQL_PassWord = yourmysqlrootpassword

######~ Set MySQL Database you want to backup ~ ###### Set the database to be partially added: Backup_Database_Name5 = database name. the numbers following Backup_Database_Name increase sequentially.
Backup_Database_Name1 = vpser
Backup_Database_Name2 = licess
Backup_Database_Name3 = junge
Backup_Database_Name4 = vpserorg

######~ Set FTP Information ~ ###### Set FTP information for storing backup data
FTP_HostName = 184.168.192.43 // IP address or domain name of the FTP server
FTP_UserName = vpsernet // FTP server username
FTP_PassWord = yourftppassword // password of the FTP server user
FTP_BackupDir = backup // backup to the FTP directory, which must be created in advance.

# Values Setting END!

TodayWWWBackup = www-*-$ (date + "% Y % m % d" 2.16.tar.gz
TodayDBBackup = db-*-$ (date + "% Y % m % d"). SQL
OldWWWBackup = www-*-$ (date-d-3day + "% Y % m % d" 2.16.tar.gz
OldDBBackup = db-*-$ (date-d-3day + "% Y % m % d"). SQL

Tar zcf/home/backup/www-$ Backup_Dir1-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir1 -- exclude = soft
Tar zcf/home/backup/www-$ Backup_Dir2-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir2
Tar zcf/home/backup/www-$ Backup_Dir3-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir3 -- exclude = test
Tar zcf/home/backup/www-$ Backup_Dir4-$ (date + "% Y % m % d" 2.16.tar.gz-C/home/wwwroot/$ Backup_Dir4

### The preceding section backs up website file data because my website is scattered and some directories under the website directory are temporary directories and do not need to be backed up, therefore, you can add -- exclude = non-backup directory. If Backup_Dir5 = yourdir is added, add tar zcf/home/backup/www-$ Backup_Dir5-$ (date + "% Y % m % d" 2.16.tar.gz-C
/Home/wwwroot/$ Backup_Dir5. If redundant, delete the redundant rows.

/Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name1>/home/backup/db-$ Backup_Database_Name1-$ (date + "% Y % m % d "). SQL
/Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name2>/home/backup/db-$ Backup_Database_Name2-$ (date + "% Y % m % d "). SQL
/Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name3>/home/backup/db-$ Backup_Database_Name3-$ (date + "% Y % m % d "). SQL
/Usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name4>/home/backup/db-$ Backup_Database_Name4-$ (date + "% Y % m % d "). SQL

### Back up the MySQL database. if Backup_Database_Name5 = yourdatabasename is added to the front, add/usr/local/mysql/bin/mysqldump-u $ MYSQL_UserName-p $ MYSQL_PassWord $ Backup_Database_Name5>/home/backup/db-$ Backup_Database_Name5-$ (date + "% Y "% m % d "). SQL. If redundant, delete the redundant rows.

Rm $ OldWWWBackup
Rm $ OldDBBackup
### Delete a backup three days ago ###

Cd/home/backup/

### Here is the automatic Upload part. I have to say that lftp is very powerful. abandon ftp ####
Lftp $ FTP_HostName-u $ FTP_UserName, $ FTP_PassWord <EOF
Cd $ FTP_BackupDir
Mrm $ OldWWWBackup
Mrm $ OldDBBackup
Mput $ TodayWWWBackup
Mput $ TodayDBBackup
Bye
EOF

Script: http://www.centoscn.com/tool/backup.sh

Download the script, put the script under/root/, modify the parameters in the script according to the above annotation, and save the script. if you are not familiar with vi or nano editor, use winscp to execute: chmod + x/root/backup. sh adds the execution permission for the script. execute: crontab-e to add scheduled execution.

Add: 0 3 ***/root/backup. sh to crontab.

The/root/bakcup. sh script is automatically executed at A.M. to back up vps data and upload it to FTP.

Reprinted please indicate the source: VPS detective link address: http://www.vpser.net/security/linux-autobackup-ftp.html

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.