日归档脚本

声明:允许转载,转载请注明链接,谢谢合作!
下面分享一个我在工作中使用的每天归档文件的脚本。
主要的功能就是备份一个文件夹下的所有需要备份的文件达成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
#

posted @   feitiandamo  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示