Linux shell 对数据进行归档

  1 #!/bin/bash
  2
  3 DATE=$(date +%y%m%d)
  4 FILE=archive$DATE.tar.gz
  5 #The path to store the files you need to archive
  6 CONFIG_FILE=/tmp/zhangxl/file_to_archive
  7 DESTINATION=/tmp/zhangxl/$FILE
  8
  9 if [ -f $CONFIG_FILE ]
 10 then
 11     echo
 12 else
 13     echo
 14     echo "$CONFIG_FILE dose not exist"
 15     echo "Backup not completed due to missing Configuration File"
 16     echo
 17     exit
 18 fi
 19
 20 FILE_NO=1

 21 #Redirect Std Input to name of Config File
 22 exec < $CONFIG_FILE
 23 read FILE_NAME
 24 while [ $? -eq 0 ]
 25 do
 26     echo "file_name:" $FIEL_NAME
 27     if [ -f $FILE_NAME -o -d $FILE_NAME ]
 28     then
 29 #   FILE_LIST="$FILE_NAME"

    #注意这个变量,我过与自信,手打变量,结果打错了,拼写成FIEL,造成没有输出
 30         FILE_LIST="$FILE_LIST $FILE_NAME"    
 31         echo "==FILE_LIST==" $FILE_LIST
 32         echo
 33     else
 34         echo
 35         echo "$FILE_NAME ,dose not exist"
 36         echo "Obviously, I will not include it in this archive."
 37         echo "It is listed on line $FILE_NO of the config file."
 38         echo "Continuing to build archive list..."
 39         echo
 40     fi
 41     FILE_NO=$[$FILE_NO + 1 ]
 42     read FILE_NAME
 43 done
 44 echo "Startin archive . . ."
 45 echo
 46 tar  -zcf $DESTINATION   $FILE_LIST  2>/dev/null
 47 echo "Archive completed"
 48 echo "Resulting archive file is :$DESTINATION"
 49 echo
 50 exit

posted on 2020-12-07 08:41  如尘如水  阅读(237)  评论(0编辑  收藏  举报