您的位置:首页 > 运维架构 > Shell

使用shell脚本进行系统备份

2014-06-12 14:42 537 查看
#!/bin/bash
#
#daily_archive - Archive designated files & directories
##################################
#
#Gather Current Date
Date=`date +%y%m%d`
#
#set archive file name
FILE=archive$DATE.tar.gz
#
#set configuration and destination file
CONFIG_FILE=/home/user/archive/Files_To_Archive
DESTINATION=/home/user/archive/$FILE

#######  main script  #############

if [ -f $CONFIG_FILE ];then
echo
else
echo
echo "$CONFIG_FILE does NOT exist"
echo "Backup not completed due to missing configuration file"
echo
exit
fi

FILE_NO=1
exec < $CONFIG_FILE

read FILE_NAME
while [ $? -eq 0 ]
do
if [ -f $FILE_NAME -o -d $FILENAME ];then
FILE_LIST="$FILE_LIST $FILE_NAME"
else
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]
read FILE_NAME
done

########################################
#   Backup the files and compress  archive

tar -czf $DESTINATION $FILE_LIST 2>/dev/null
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: