Practical: Linux regular automatic backup script

Source: Internet
Author: User
We often need to back up some data in our online maintenance work. Although the work is not complicated, it takes a lot of time. I will share a Linux backup script here to implement automatic backup with ease and

During our online maintenance work, we often need to back up some data. although it is not complicated, it takes a lot of time. I will share a Linux backup script here to implement automatic backup with ease, in addition, the files backed up in N days can be retained. this script is divided into two files, one of which is the execution file backup. sh. lst.

# Backup. sh

-- Important variable name function

LogFile

Directory to be backed up by SourceDir

BakDir back up to this directory

RetainDay backup file retention days

ProjectLst backup project file configuration file

The code is as follows:

  1. #! /Bin/bash # author: InBi # date: 2011-07-28 # role: backup files periodically. # website: http://www.itwhy.org/2011/07-28/707.html##################################################LogFile=/backup/log/ 'Date + "% Y-% m "'. logDATE = 'date + "% Y-% m-% d" 'sourcedir =/var/RDfileBakDir =/backupRetainDay = 20 ProjectLst =/backup/project. lst ####################################### ########## echo "backup start at $ (date +" % Y-% m-% d % H: % M: % S ")"> $ LogFileecho "success" >>$ LogFilecd $ BakDirPROJECTLIST = 'cat $ projectlst' for Project in $ PROJECTLISTdoProjectData = $ SourceDir/$ ProjectDe StDir = $ BakDir/$ ProjectPackFile = $ DATE. $ Project. tgzif [-f $ BakDir/$ PackFile] thenecho "backup file have exist! ">>$ LogFileelsecp-RHpf $ ProjectData $ DestDir>/dev/nulltar-zcvf $ PackFile $ Project>/dev/nullecho" backup $ Project done into $ PackFile ">$ LogFilerm -rf $ ProjectfiOldFile = "$ BakDir/" $ (date -- date = "$ RetainDay days ago" + "% Y-% m-% d "). $ Project. tgzif [-f $ OldFile] thenrm-f $ OldFile>/dev/nullecho "[$ OldFile], Delete Old File Success! ">>$ LogFilefiecho" ">>$ LogFiledoneecho" -------------------------------------------------- ">>$ LogFileecho" backup end at $ (date + "% Y-% m-% d % H: % M: % S ")" >>$ LogFileecho "" >>$ LogFileexit 0

# Project. lst: This file is a text file. each line of it represents a project, that is, the files or directories under the Directory you want to back up.

Onu_armonu_voiponu_wifi5xxx7xxx8xxxnms

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.