One-click and automatic backup of Linux VPS files/database script functions and applications

888u

Last update at :2024-07-08,Edit by888u

Every year, Snail sees a lot of netizens complaining about how the hosting providers have caused their data to be lost. Some webmasters have never backed up their websites after choosing VPS or servers to set up their websites. If this is possible, If the hosting provider's disk is damaged and lost, the data cannot be recovered, so the consequences can be imagined. Host providers certainly have their reasons, but no matter which host we choose, it is ourselves who need to be backed up, and we cannot rely too much on the merchants.

Even we need multi-method and multi-channel backup. Last week, Snail met a netizen who backed up a certain host through a snapshot, but the migration data could not be started when restoring. The data was backed up into a snapshot, but it could not be restored. the result of. Of course, Snail will also toss a lot of VPS every year, and some businesses that think they are relatively stable will relax their backup vigilance. For example, the resource library that has been used to store scripts and resources was unable to recover the data due to a broken disk some time ago. This shows the importance of backup.

Each of us has our own way of backing up the website, including direct manual download and copy backup, the website's own backup function, exporting the database package file to download the backup, and more advanced users implementing automatic off-site backup. Anyway, no matter what, we can choose what suits us. Even if the data is not too important, we must have certain backup rules. Anyway, if something goes wrong, most of the data will be there.

Snail has previously shared articles about backing up websites and databases:

1. OneinStack comes with local/remote backup website files and database usage methods

2. Detailed explanation of how to use the mysqldump command to back up and restore MySQL data

3. Four common methods for backing up MYSQL databases on Linux VPS hosts

In this article, Snail saw a backup database script posted by teddysun on his blog, which can automatically back up to a local server and also back up to a Google Drive network disk.

First, preparations

1. This is the first time I have used this script, so before using it, we recommend testing it on a test machine or backing up existing data to avoid adverse symptoms.

2. According to the introduction, you can back up the entire database MySQL/MariaDB, or specify a database user to back up.

3. It also supports uploading files directly to remote FTP space and backing up to Google Drive network disk.

4. The script of this article comes from https://teddysun.com/469.html. The official version shall prevail for details. Thanks to teddysun for providing the script.

Second, one-click backup script download and authorization

wget –no-check-certificate https://github.com/teddysun/across/raw/master/backup.shchmod +x backup.sh

Third, modify the file configuration parameters

Before executing the script, we need to modify the backup.sh parameters first. The content is rich and the modification needs to be detailed.

1. Basic parameters

ENCRYPTFLG: true Set encryption BACKUPPASS: Set packaging encryption password LOCALDIR: Set the backup directory, according to our actual one-click package or panel settings TEMPDIR: Backup temporary directory LOGFILE: Log file when the script is run MYSQL_ROOT_PASSWORD: ROOT database management password MYSQL_DATABASE_NAME :Specify the backup database name. If you don’t write it, all database users will be backed up

Note: MYSQL_DATABASE_NAME is in the form of an array. If multiple database names are backed up at one time, we copy and modify the array parameters in sequence.

2. Specify backup files

We can only back up the above database, or we can set up the backup website file directory through this script.

We can set the backup directory in BACKUP[0]=\\"\\", which is also in array form. If there are multiple websites to be backed up, the format is copied in array form.

3. Remote FTP space information

FTP_FLG: Whether to upload to the remote FTP space, true means uploading FTP_HOST: Remote FTP server IP address FTP_USER: Remote FTP server user FTP_PASS: Remote FTP server password FTP_DIR: Remote server backup directory folder, can be specified

Fourth, experience of executing backup script

./backup.sh

After we modify the parameters here, we can script the backup process by ourselves.

Even if we need to set up scheduled backup later, we still need to manually test whether the script is normal. Here I simply back up the database for testing. You can see that there are no errors in the execution, and there is a backed up database in the corresponding backup directory.

Fifth, decrypt and decompress files

Whether we are backing up to a local server or a remote FTP space, it is recommended to use encryption, so that even if the FTP space files are leaked, there will be at least one relatively safe guarantee. The files we backed up here are in .ENC encrypted format, and we need to decrypt them first and then decompress them.

1. Decryption format

openssl enc -aes256 -in [decrypted file name] -out decrypted folder compression package.tgz -pass pass: [set encryption password] -d -md sha1

2. Decompress

tar -zxPf [compressed package name]

Sixth, set a scheduled run

30 1 * * * root bash /root/backup.sh

If we want to implement automatic scheduled backup operation, we can add it to the crontab scheduled script for execution.

Finally, this script also comes with backup to Google Cloud Drive. If necessary, you can refer to the official website to set it up. Generally, it is enough for us to back up to local or remote backup in our own FTP space.

Recommended site searches: domain name list, Wanwang space, registration-free cdn acceleration, how to bind a domain name to a server, US multi-ip station group vps, which Hong Kong space is better, website virtual host, how to cancel domain name registration, what is needed for website registration , Hong Kong server,

One-click and automatic backup of Linux VPS files/database script functions and applications

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码