Linux VPS automatic backup website and MYSQL database script

Time:2019-10-9

Prepare to have a built LNMP key environment packaged with regular backup database and website files and uploaded directly to the spare FTP space. For example, you can find some virtual host space, hard disk storage is relatively large, can be used as standby data directly.

First, preparation before backup

1. Prepare an FTP host space

2. When using this script for the first time, we need to backup the data in case of emergency.

3. At present, I am testing in LNMP keypack environment.

4. Install sendmail component (yum install sendmail mutt)

Second, download scripts

http://www.cnbanwagong.com/tools/backup-ftp.sh

Third, modifying configuration files

#!/bin/bash
# Here's where you need to modify it.
MYSQL_USER=root#mysql username
MYSQL_PASS=123456#mysql password
MAIL_TO=mailbox sent by [email protected] database
FTP_USER=cat#ftp username
FTP_PASS=123456 FTP password
FTP_IP=123.123.123.123#ftp address
FTP_backup = backup ftp, the directory where backup files are stored, which you have to build on ftp.
WEB_DATA=/home/www/cnbanwagong.com# Web site data to be backed up
# Where you want to change ends here.

Modify according to our actual information. Then replace it to the server.

Fourth, set up authority and set periodic execution

1. Setting permissions

chmod +x /root/backup-ftp.sh

2. Setting Timing

crontab -e

Then add the execution script

00 01 * * * /root/backup-ftp.sh

Set to be executed at 1 a.m. every day.

3. Is the test valid?

sh /root/backup-ftp.sh

Here we can perform a look, if the normal backup to FTP space, that is no problem, if there is a problem, we can re-check.

Recommended Today

WebSocket series of binary data design and transmission

An overview of the Through the first three blogs, we can understand how the data we need to pass before sending data through WebSocket becomes ArrayBuffer binary data. After we received the binary data, how we turned it into a common data type in JavaScript.This article, the fourth in the WebSocket series, will use a […]