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

linux 数据备份

2016-07-07 20:20 483 查看
#!/bin/bash

DATE=$(date '+%m%d%y')

FILE=archive$DATE.tar.gz

CONFIG_FILE=/home/user/archive/Files_To_Backup   //注解 Files_To_Backup 该文件里存放需要备份的目录,文件

DESTINATION=/home/user/archive/$File

#Check Backup Config file exists

if [ -f $CONFIG_FILE ]

then

echo

else

echo

echo "$CONFIG_FILE dose not exist."

echo "Backup not completed due to missing Configuration File"

echo

exit

fi

#Bulid the names of all the files to backup

FILE_NO=1

exec < $CONFIG_FILE

read FILE_NAME

while [ $? -eq 0 ]

do

if [  -f $FILE_NAME -o  -d $FILE_NAME ]

then

#if the file exists,add its name to the list.

FILE_LIST="$FILE_LIST $FILE_NAME"

else

# if the file doesn't exist,issue waring

echo

echo "$FILE_NAME ,dose not exist."

echo "Obviously,I will not include it in this archive."

echo “It is listed on the 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




在 /home/user/archive 会存在备份好的压缩文件,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: