Linux 定期自动备份脚本

这是一个简章的利用tar备份的脚本!虽然没有什么技术性,但有时也有帮助。

backup.sh

#!/bin/bash
#author:        InBi
#date:          2011-08-05
#role:          backup files periodically.
#website:       http://www.itwhy.org/2011/07-28/707.html
##################################################
LogFile=/backup/log/`date +"%Y-%m"`.log
SourceDir=/var/RDfile
BakDir=/backup
RetainDay=20
ProjectLst=/backup/project.lst
##################################################
DATE=`date +"%Y-%m-%d"`
echo "backup start at $(date +"%Y-%m-%d %H:%M:%S")" >$LogFile
echo "--------------------------------------------------" >>$LogFile
cd $BakDir
PROJECTLIST=`cat $ProjectLst`
for Project in $PROJECTLIST
do
	ProjectData=$SourceDir/$Project
	DestDir=$BakDir/$Project
	PackFile=$DATE.$Project.tgz
	if [ -f $BakDir/$PackFile ]
	then
		echo "backup file have exist !" >>$LogFile
	else
		cp -RHpf $ProjectData $DestDir >/dev/null
		tar -zcvf $PackFile $Project >/dev/null
		echo "backup $Project done into $PackFile" >>$LogFile
		rm -rf $Project
	fi
done
find $Bakdir -type f -mtime +$RetainDay -name "*.$Project.tgz" -exec rm {} \; >/dev/null
echo "--------------------------------------------------" >>$LogFile
echo "backup end at $(date +"%Y-%m-%d %H:%M:%S")" >>$LogFile
echo " " >> $LogFile
exit 0

project.lst

onu_arm
onu_voip
onu_wifi
5xxx
7xxx
8xxx
nms

你可能感兴趣的:(linux,备份)