In linux, the backup is automatically packaged and deleted five days ago.

Source: Internet
Author: User

In linux, the backup is automatically packaged and deleted five days ago.

Project requirements

1. Automatically package a file directory,

2. The package file is automatically placed in a specified directory.

3. The files generated five days ago are automatically cleared;

Implementation:

1. Use crontab for Scheduled Backup

2. Use tar for compression

3. Use shell to calculate the date and remove the old file.

4. Add the backup file baksvn to the/usr/sbin directory.

#! /Bin/sh
Rq = 'date + % Y % m % d'
Rm-f/home/svnbak/'date-d'-5 days 'using policyuncm=d'.tar.gz
Tar zcvf/home/svnbak/$rq.tar.gz/var/svn/document


Likewise, mysql backup can be implemented.

You only need to add

Mysqldump-uroot-p XXXXXX>/home/XXXXXXx_bak_20150108.dat

As follows:

#! /Bin/sh
Rq = 'date + % Y % m % d'

Mysqldump-uroot-p XXXXXX>/home/XXXXXXx_bak _ $ rq. dat
Rm-f/home/svnbak/'date-d'-5 days 'using policyuncm=d'.tar.gz
Tar zcvf/home/svnbak/$rq.tar.gz/var/svn/document



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.