Jump to content

I have previously mentioned how to automatically backup FTP and databases on Linux VPS daily, but you need to build your own FTP space, which is a bit troublesome than this tutorial. If you don’t have FTP space, you can apply for a Qiniu Cloud Storage. Free 10G space backup is enough for ordinary small sites. Here is a script to backup website files and databases to Qiniu. The actual test results are pretty good. You can automatically backup them every day by setting up a scheduled task under Linux vps. The Github project address of this script: https://github.com/ccbikai/backuptoqiniu

First register a Qiniu Cloud account, and then after real-name authentication, you will get 10G of traffic and space. After registering, find the object storage at the left position, then create a new storage space, and remember the name of the newly created storage space, which you need to use later.QQ截图20190603094246.png

Method

Note: The system python version must be above 2.7

1. Install zip

apt-get install zip Note: the centos command is

yum install zip

2. Install the backup script

wget --no-check-certificate -O backuptoqiniu.zip https://www.moerats.com/usr/down/backuptoqiniu.zip

unzip backuptoqiniu.zip cd backuptoqiniu

python setup.py install

3. Edit configuration file

Use vi backuptoqiniu.sh command or Winscp tool to edit

##Backup Configuration Information ##

#Backup name, used to mark

BACKUP_NAME='backup'

#Backup directory, please separate multiple spaces

BACKUP_SRC='/home/wwwroot/moerats.com'

#Mysql host address

MYSQL_SERVER='localhost'

#Mysql username

MYSQL_USER='root'

#Mysql Password

MYSQL_PASS='mysqlpassword'

#Mysql backup database, please separate multiple spaces

MYSQL_DBS='dbname'

#Replace the file temporarily in the directory, generally no changes are required

BACKUP_DIR='/tmp/backuptoqiniu'

#Back up file compression password to ensure the security of the compressed package

BACKUP_FILE_PASSWD='123456'

##Backup Configuration Information End ##

##Qi Niu Configuration Information ##

#Storage space corresponds to the folder we created on Qiniu

QINIU_BUCKET='Rats'

QINIU_ACCESS_KEY='ACCESS_KEY'

QINIU_SECRET_KEY='SECRET_KEY'

##Qi Niu Configuration Information End ##The script configuration above has basically been written very clearly. The first half of the website is filled in, and the last three lines of information are obtained in Qi Niu. QINIU_BUCKET is the storage space name, ACCESS_KEY and SECRET_KEY are obtained in the personal panel-key management. The long list of AK and SK that corresponds to is the key.

4. Test script

chmod +x backuptoqiniu.sh

After ./backuptoqiniu.sh is running normally, we can go to the Qiniu background to check if there is any compressed package in the newly created storage space.

5. Set up automatic running scripts

crontab -e

0 2 * * 0 /bin//root/backuptoqiniu/backuptoqiniu.sh #Add this script The above script means to use crontab timed tasks to automatically run this script at 2 a.m. every day. For specific usage of crontab, please refer to the file. Detailed explanation of the commands for the installation of Crontab of Linux system and timing tasks

Note: Many times our VPS needs to use the timing function when running scripts or restarting certain software. At this time, we need to use the Crontab timing software.

Note: If you are using foreign vps, you may also need to set it to domestic time by CP /usr/share/zoneinfo/Asia/Shanghai /etc/localtime.

Then service cron restart starts your scheduled task.

The effect is as follows

QQ截图20190603094759.png

You can view the backup files in Qiniu Cloud QQ截图20190603094859.png

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...