日归档脚本

声明:允许转载,转载请注明链接,谢谢合作!
下面分享一个我在工作中使用的每天归档文件的脚本。
主要的功能就是备份一个文件夹下的所有需要备份的文件达成tar包
脚本 如下:
#!/bin/sh
#daily_archive.sh     脚本名称
#Daily_Archive - Archive designated files & directories
#日归档脚本,定向备份文件和目录
#OPERATE_DATE         操作数据日期
#author:wangxin     version:1.0 
#create_date:20160114
##################################################################
#Gather Current Date
#获取当前日期
OPERATE_DATE=`date +%y%m%d`
#
#Set Archive File Name
#设置归档文件的文件名
FILE=archive29_$OPERATE_DATE.tar.gz
#
# Set Configuration and Destination File
#设置配置文件和目标目录
#
FILE_NAME=archive_filename.txt
CONFIG_FILE=/data01/backup/$FILE_NAME
DESTINATION=/data01/backup/$FILE
#
##############   Main   Script   #########################
#主脚本
find   /home/hadoop/ -name '*.*' -exec ls {} \; > /data01/backup/$FILE_NAME
#使用find 得出需要备份的目录的所有符合正则表达式的文件
# Check Backup Config file exists
#检查需要备份的配置文件是否存在
#
if [ -f $CONFIG_FILE ]   # Make sure the config file still exists
then                 # If it exists. 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 directory 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 dosen't 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 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
#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值