4>>shell--backup-daily

#!/bin/bash
#
#This is a test in book.thanks for Richard Blum.
#Please put this file to crontab,thanks.
#Please touch a new configuration file.
#Daily_Archive - Archive designated files & directories
#
##########################################################
#
#Gather Current Date.the format of date is only " date +%d%m%y".
#
#
DATE=`date +%y%m%d`
#
echo $DATE
#Set Archive File Name
#
FILE=backup$DATE.tar.gz
#
#Set Configuration and Destination File.The configuration file include directories that you want to backup.
#
CONFIG_FILE=/home/ach/test/shell-practices/backup-daily.conf
DESTINATION=/home/ach/backup/$FILE
#
############ Main Script ##################################
#
#Check Backup Config file exists
#
if [ -f $CONFIG_FILE ] #Make sure the config file still exists.
then #If it existd,do nothing but continue on.
echo
else #If it doesn‘t exist,issue error & exit script.
echo
echo "$CONFIG_FILE does not exist."
echo "Backup not completed due to missing Configuration File."
echo
exit
fi
#
#Build the names of all the files to backup
#
FILE_NO=1 #Start on Line 1 of Config File
exec < $CONFIG_FILE #Redirect Std Input to name of Config File.
#
read FILE_NAME #read 1st record.
#
while [ $? -eq 0 ] #Create list of files to backup
do
#Make sure the file or directories exists.
if [ -f $FILE_NAME -o -d $FILE_NAME ]
then
#If file exists, add its name to the list.
FILE_LIST="$FILE_LIST $FILE_NAME"
else
#If file does not exist,issue warning.
echo
echo "FILE_NAME does not exist."
echo "Obviously,I will not include it in this archive."
echo "It is listed on line $FILE_NO of the config file."
echo "Continuing to build archive list......"
echo
fi
#
FILE_NO=$[FILE_NO+1] #Increase Line/File number by one.
read FILE_NAME #read next record.
done
#
############################################################
#
#Backup the files and compress archive
#
tar -czf $DESTINATION $FILE_LIST 2> /dev/null
#To decompress use command : -xf (extract)
#END with the backup-daily
#Next is backup-hour,which will use a new method that can level directories.
#
#DAY=`date +%d`
#MONTH=`date +%m`
#TIME=`date +%M`
#
#mkdir -p $BASEDEST/$MONTH/$DAY
#
#DESTINATION=$BASEDEST/$MONTH/$DAY/$TIME.tar.gz
#
#
#
##END

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。