Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize regular automatic backup and deletion of website data by Linux system

Shulou Source: shulou.com Published: 2022-06-01 07:34:25 10月02日 Update

The main content of this article is "how to achieve regular automatic backup and deletion of website data in Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to achieve regular automatic backup and deletion of website data by the Linux system".

The requirements are as follows: first, the website files and databases need to be backed up automatically every day, and then the backup directory will be deleted for more than a certain period of time, such as keeping the backup for the last 14 days.

It just so happens that vps is redhat, but there is no crond service installed by default. Enter the following command to install it.

Yum install cronie

Create a backup script

Vi / root/bakweb.sh

Edit and enter the following

#! / bin/bash

Find / home/bak/-name'*'- type f-mtime + 14-exec rm {}\

Tar zcvf / home/bak/www.penglei.name_$ (date +% F) .tar.gz / var/www/html

Mysqldump-u root-- password=PASSWORD DBNAME >

/ home/bak/sql.penglei.name_$ (date +% F) .sql

Exit 0 input: wq save exit. The script means to first select / home/bak as the site backup directory.

The first step is to delete files under / home/bak for more than 14 days

The second step is to back up the website directory / var/www/html by www.jb51.name_+ date for the file name

Third, export the database for the file name by sql.penglei.name_+ date, and replace PASSWORD and DBNAME with your own root password and database name.

Finally, create a crond script, which can be run automatically at 5 o'clock every morning to create the crond file.

Vi / etc/cron.d/bakweb edit and enter the following

0 5 * root/ root/bakweb.sh

At this point, I believe you have a deeper understanding of "how to achieve regular automatic backup and deletion of website data by the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Backup website data file content script input system database directory file name date learning practical deeper interest command world practicality actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Huawei Shulou Technology Shulou Tech Info