VPS automatic backup Shell script

VPS automatic backup Shell script

VPS automatic backup Shell script, used to back up and manage MySQL database and Web data on Linux system with one click, and automatically upload to the remote backup server.

1. Features and functions

1. Pure shell script, easy to use, low technical threshold, easy to modify, and can be uninstalled by deleting.
2. You can specify the frequency of data backup and the number of backups to be saved, and automatically delete unnecessary old backups.
3. You can specify multiple Mysql databases that need to be backed up, and even exclude a database from being backed up.
4. You can specify multiple data directories that need to be backed up, and even support secondary directory package backup.
5. Support local and multiple backup (ftp, scp, amazon s3), and optional full and incremental backup for off-site backup.

2. Download and Use

2.1. Download the script

https://gist.github.com/1505857

 1
2
3
 wget http://wangyan.org/download/shell/vps_auto_backup.sh
chmod 100 vps_auto_backup.sh
mkdir /var/shell && mv vps_auto_backup.sh /var/shell

2.2. Set up cron daemon

The frequency of automatic execution can be set at will, usually once an hour is sufficient.

 1
2
 crontab -e
0 * * * * /bin/bash /var/script/sys-mon.sh

2.3. Install additional software

If you need to perform remote FTP or SCP backup, you need to install lftp and expect.

 1
2
 yum -y install lftp expect #centos
apt-get -y install lftp expect #ubuntu

Configuration Options

# Backup data storage directory

 1
 BACKUP_DIR="/root/vps-bak"

MySQL backup options

# Whether to enable MySQL backup, 0 means disable, 1 means enable.

 1
 ENABLE_MYSQL_BACKUP="1"

# Database backup interval, 1 hour = 3600 seconds.

 1
 MYSQL_BACKUP_CYCLE="43200"

# The number of database backups to save. By default, the latest 4 backups are saved.
# For example: backup twice a day, and need to save the backup of the last two days, then fill in "4" here

 1
 MYSQL_BACKUP_NUM="4"

# Database host, username, password.

 1
2
3
 MYSQL_HOST="localhost"
MYSQL_USER="root"
MYSQL_PWD="123456"

# The name of the database to be backed up. Multiple databases should be separated by spaces. "all" means all databases.

 1
 MYSQL_DB_NAMES="all"

# The name of the database that needs to be excluded from the backup. Multiple databases should be separated by "|".

 1
 MYSQL_EXCLUDE_DB="phpmyadmin|information_schema|performance_schema"

Web backup options

# Whether to enable local backup of Web data. 0 means disable and 1 means enable.

 1
 ENABLE_LOCAL_BACKUP="1"

# Data backup interval, 1 hour = 3600 seconds.

 1
 WWW_BACKUP_CYCLE="86400"

# The number of data backups to be saved. By default, the most recent two backups are saved.
# For example: backup once a day, and need to save the backup of the last two days, then fill in "2" here

 1
 WWW_BACKUP_NUM="2"

# The data source directory that needs to be backed up. Multiple directories should be separated by spaces.

 1
 WWW_BACKUP_DIRS="/home /var/www"

# The depth of the data source directory to be backed up, folder=0, folder+subfolder=1

 1
 WWW_BACKUP_DEPTH="1"

FTP backup options

# Whether to enable remote FTP backup. 0 means disable and 1 means enable.

 1
 ENABLE_FTP_BACKUP="0"

# FTP backup interval, 0 means disabled, 1 hour = 3600 seconds

 1
 FTP_BACKUP_CYCLE="0"

# FTP backup mode, full backup = 0, incremental backup = 1

 1
 FTP_BACKUP_MODE="0"

# The remote FTP storage backup folder. If it does not exist, the script will automatically create it.

 1
 FTP_REMOTE_DIR="vps-bak"

# Remote FTP host, username, and password.

 1
2
3
 FTP_HOSTNAME="192.168.8.128"
FTP_USERNAME="test"
FTP_PASSWORD="test"

SCP backup options

# Whether to enable remote scp backup, 0 means disable, 1 means enable.
# Note: To support certificate-free login, you need to install "expect" (yum -y install expect)

 1
 ENABLE_SCP_BACKUP="0"

# SCP backup interval, 0 means disabled, 1 hour = 3600 seconds

 1
 SCP_BACKUP_CYCLE="0"

# Remote host, username, password.

 1
2
3
 SCP_HOST="192.168.8.128"
SCP_USER="root"
SCP_PASSWD="123456"

# The remote host stores the backup folder.

 1
 SCP_REMOTE_PATH="/root/vps-bak"

Amazon S3 backup options

# Whether to enable Amazon s3 backup, 0 is disabled, 1 is enabled.

 1
 ENABLE_S3_BACKUP="0"

# Amazon s3 backup interval, 0 means disabled, 1 hour = 3600 seconds

 1
 S3_BACKUP_CYCLE="0"

# Amazon s3 backup mode, full backup = 0, incremental backup = 1

 1
 S3_BACKUP_MODE="0"

# Amazon s3 BUCKET name. If it does not exist, the script will automatically create it.

 1
 S3_BUCKET="vps-bak"

# Amazon access key

 1
 ACCESS_KEY_ID="123456"

# Amazon secret access key

 1
 SECRET_ACCESS_KEY="123456"

4. Suggestions and Feedback

If you find errors in the script or have better suggestions, you can leave a message or send an email to:

myidwy(at)gmail.com

 Reprinted from: http://wangyan.org/blog/vps-backup-shell-script.html

<<:  Cheap and stable foreign VPS

>>:  Canadian Hosting Provider - MyHosting Hosting Introduction

Recommend

Free Alpha SSL Certificate

1. The free SSL certificate is an Alpha SSL certi...

SeedHost: €45/month/X3440/8GB RAM/8TB HDD/100TB traffic/1Gbps/Netherlands

SeedHost, a Dutch business, was founded in 2008. ...

OVH D-1521 32GB RAM 72TB hard drive unlimited traffic French dedicated server review

Configuration is Intel Xeon D-1521 – 4c/8t – 2,4G...

$50/month/2G/500G/3TB dedicated server——Umbra Hosting

According to official information, Umbra Hosting ...

Delimiter: $20/month/Dual E5420/16GB memory/1TB space/10TB traffic/1 IP

Delimiter, a low-cost dedicated server provider, ...