Operation and maintenance notes - script: time to move back up files to a specified directory

Scene Description:

An application system, the relevant backup files in the directory: / usr / data_bak / backups

With the accumulation time, the backup file generated by the system is increasing every day, the day of the backup files generated greater than 10G.

 

Cause problems:

  1. System disk disk space is not large, single backup file is too large to store about three days, the alarm system disk disk space will lead to a new generation of backup files can not be normal.
  2. Backup file in the default configuration directory, the directory should be archived in a unified

Disposition:

    Script content, every morning 6:10 to backup files, move to the specified backup directory.

    Script Name: mv_cron.sh

    Script Content:

#! /bin/bash
path1="/usr/data_bak/"
path2="/home/data_bak/pg_bak/"
timelimit1="+6"
timelimit2="-17"
for i in "backups"; do
        list_newfiles=`cd $path1$i && find -iname "*.zip" -type f | awk '{print substr($1,3)}'`
        echo ""
        echo "target folder: $path2"
        echo "Trying to move those files in $path1$i"
        echo "$list_newfiles"
        echo ""
        OLD_IFS=$IFS
        IFS=$'\n'
        arr_newfiles=($list_newfiles)
        for s in ${arr_newfiles[@]}; do
                #echo "$s"
                isfindthisfile=`find $path2 -iname $s`
                if [ -z "$isfindthisfile" ]; then
                        echo "$path1$i/$s is not in target folder,try to copy!"
                        mv "$path1$i/$s" "$path2/$s.TMP"
                        mv "$path2/$s.TMP" "$path2/$s"
                        echo "$path1$i/$s has been moved successfully!!!"
                else
                        echo "$path1$i/$s is allready in target folder,trying to copy next !"
                fi
        done
done
IFS=$OLD_IFS

Script Description:

    path1 is the current system backup file directory,

    path2 directory is a destination for the backup file.

    Line 7, according to their actual extension of the backup file, find, here it is a .zip file.

Timing Task Configuration:

    Crontab configuration comes with the system, every morning 6:10 to execute the script. crontab -e inside add the following:

     10 06 * * * /data/mv_cron.sh

 

Guess you like

Origin www.cnblogs.com/hellojesson/p/11584446.html