Use crontab in linux to implement regular backup

Source: Internet
Author: User
In linux, use crontab to implement regular backup-Linux Enterprise Application-Linux server application information. The following is a detailed description. Recently, all source code in cvs needs to be regularly backed up. The following method is briefly summarized:

1. log in as root and create a script file

For example, if I want to back up all the files in the/home/software/Temp directory, and store the backup files under/home/software,

Create a backup script in the/home/software Directory and name it backup. sh:

$ Vim backup. sh

# Shell Content

YMD = 'date + % Y % m % d'

Backname1_temp-bak-policymd.tar.gz

Cd/home/software

Tar czvf $ BACKNAME./Temp

# Setting the backup file permission to make it accessible to user software

Chown software: software $ BACKNAME


2. Modify the read and write permissions of the script file (backup. sh. (This step cannot be ignored)

$ Chmod 700 backup. sh

$ Chown software backup. sh

3. scheduled execution configuration file

$ Crontab-e

The execution result of this command is to edit a scheduled execution configuration file. Enter the following line:

30 20 ***/home/software/backup. sh

This statement means: Execute the backup script at 08:30 every night and save the disk and exit.

4. Supplement

Crontab basic usage:

1. crontab? L
List the current crontab task
2. crontab? D
Delete the current crontab task
3. crontab-e
Edit a crontab task and ctrl_D ends.
4. crontab filename
Use filename as the crontab task list file and load it

Crontab file format: ***** cmd
Rows in the crontab file are composed of six fields. Different fields are separated by spaces or the tab key. The first five fields specify the time when the command will be run.
Minutes (0-59)
Hour (0-23)
Date (1-31)
Month (1-12)
Day of the week (0-6, 0 indicates Sunday)
The 6th fields are strings to be executed at the appropriate time

So far, you can make linux back up all the files under/home/software/Temp to/home/software at 08:30 every night.
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.