日归档脚本
  声明:允许转载,转载请注明链接,谢谢合作!
 
 下面分享一个我在工作中使用的每天归档文件的脚本。 
 
  主要的功能就是备份一个文件夹下的所有需要备份的文件达成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.
          
 
  
   else  
     
     
     
     
     
     
     
    # If it doesn't exist.issue error & exit script.
          
 
  
   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
  
 
  
   #
  
 
  
   done
  
 
  
   #
  
 
  
    #####################################################################
  
 
  
   #
  
 
  
   #  
   Backup the files and Compress Archive
   
 
  
   #
  
 
  
   tar -czf $DESTINATION $FILE_LIST 2> /dev/null
  
 
  
   #
  
 
  
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号