Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Linux automatically backs up scripts on a regular basis

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Linux how to automatically backup scripts regularly, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

In the work of network maintenance, we often have to back up some data, although the matter is not complicated, but it takes a lot of time. I share a Linux backup script here, which can realize automatic backup easily and can keep N-day backup files. The script is divided into two files, one is the execution file backup.sh, and the other is the backup project file project.lst.

# backup.sh

The role of important variable names

LogFile log file

Directories that need to be backed up by SourceDir

BakDir backup to this directory

Days of retention of RetainDay backup archive files

ProjectLst backup project file configuration file

Code:

#! / 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 + "% Ymuri% m" `. LogDATE= `date + "% Y- % mmer% d "`SourceDir=/var/RDfileBakDir=/backupRetainDay=20ProjectLst=/backup/project.lst###echo" backup start at $(date + "% Y-%m-%d% H:%M:%S") "> $LogFileecho"- -- "> > $LogFilecd $BakDirPROJECTLIST= `cat $ProjectLst`for Project in $PROJECTLISTdoProjectData=$SourceDir/$ProjectDestDir=$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 easy to understand. It is a text file, each line of which represents a project, that is, a file or directory under the directory you need to back up.

Is it helpful for onu_armonu_voiponu_wifi5xxx7xxx8xxxnms to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report