In Linux, how does one Perform Batch Processing to automatically retain backups for several days?

Source: Internet
Author: User
Tags date1

In LINUX, automatic backup is very important to data security. How can we achieve automatic backup to retain data in the last few days? The following uses the bucket Classification Website www.yes81.net as an example for testing. The attachments uploaded by Forum users on the website, the attachments uploaded by the main system of the bucket and the database are an important data that must be backed up.

This server uses an array of dual hard disks, so there is no worries about data loss due to hard disk crash, mainly due to system problems or misoperations.

1. Hard Disk Partition backdata is used for backup.

2. mydata is a data partition, mysql is a database file directory, bbs is the file directory of the Forum, and yes81 is the file directory of the main site yes81.net

Now our goal is to complete the daily automatic backup, and retain only 10 days of data, the data is automatically deleted 10 days ago

For this reason, we have compiled the following automatic backup batch file, and added the task automatically executed at every morning in the crontab schedule.

----------------- Bacpupdata. bat -------------------------------------

Cd/backdata

# ---- Delete the backup 10 days ago

Date-d-15-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

Date-d-14-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

Date-d-13-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

Date-d-12-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

Date-d-11-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

Date-d-10-day + % Y-% m-% d> dd.txt

Read dateold <dd.txt

Rm dd.txt-f

Rm-rf $ dateold

# ----- Create a new file backup for the day

Date-d 0-day + % Y-% m-% d> dd.txt

Read date1 <dd.txt

Rm dd.txt-f

Mkdir $ date1

Rar a/backdata/$ date1/database1_date1.rar/mydata/mysql

Rar a/backdata/$ date1/bbs1_date1.rar/mydata/bbs/WEB-INF/lybbs/upload

Rar a/backdata/$ date1/buyi?date1.rar/mydata/yes81

The copyright of this post belongs to http://free.yes81.net/yes81/view-1169.html. For more information, please copy this address.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.