用tar编写脚本进行差量备份

#!/bin/sh
date=`date +%m%d`
sourcedir=/usr/aaa
targetdir=/home/bbb
case $1 in
        'f')
#Full Backup
        outlogname=$targetdir/FO$date.log
        inlogname=$targetdir/FI$date.log
        echo Performing full backup on `date`, logname $outlogname
        echo Performing full backup on `date`...>;$outlogname
        if [ $# -eq 2 ]
        then
                if [ $2 != '--notouch' ]
                then
                        touch $targetdir/last.backup
                else
                        echo Using the notouch option >;>;$outlogname
                fi
        else
                touch $targetdir/last.backup
        fi
        tar Pzcv $sourcedir -f $targetdir/finish$date.tar.gz >;>;$outlogname
        echo Backup completed at `date` >;>;$outlogname;;
        'i')
#Incremental backup
        outlogname=$targetdir/IO$date.log
        inlogname=$targetdir/II$date.log
        echo Performing incremental backup on `date`, logname $outlogname
        echo Performing incremental backup on `date`...>;$outlogname
        find $sourcedir -newer $targetdir/last.backup -type f -print >; $targetdir/list
        tar Pzcvf $targetdir/finish$date.tar.gz -T $targetdir/list >;>;$outlogname
        rm $targetdir/list
        echo Backup completed at `date` >;>;$outlogname;;
        'd')
#Daily backup
        outlogname=$targetdir/DO$date.log
        inlogname=$targetdir/DI$date.log
        echo Performing daily backup on `date`, logname $outlogname
        echo Performing daily backup on `date`... >;$outlogname
        find $sourcedir -newer $targetdir/last.backup -type f -print >; $targetdir/list
        tar Pzcvf $targetdir/finish$date.tar.gz -T $targetdir/list >;>;$outlogname
        rm $targetdir/list
        touch $targetdir/last.backup
        echo Backup completed at `date` >;>;$outlogname;;
        *)
#Invalid option
        echo Invalid or no parameter entered for archive on `date`;;
esac
只要按照各自的需要修改一下sourcedir和targetdir就可以了。

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS