#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
BK_HOME=/backup
MEDIA_HOME=/home/web/media
SNAPSHOT=`ls /backup/ |grep snapshot |wc -l`
TFILE=`ls /home/web/media |wc -l`
if [ "$TFILE" == 0 ]
then
echo "There is no media file exist."
else
if [ "$SNAPSHOT" != 0 ]
then
echo "-------------------------------------`date +%Y%m%d`----------------------------------"
echo "Now we compress media files."
tar -g $BK_HOME/snapshot -zcvpf $BK_HOME/image`date +%Y%m%d`_$RANDOM.tar.gz /home/web/media >/dev/null 2>&1
else
echo "--------------------------------------`date +%Y%m%d`----------------------------------">>$BK_HOME/err.log
echo "There is no snapshot or it was deleted.\n" >>$BK_HOME/err.log
echo "Rebuild snapshot and full backup media files.\n">>$BK_HOME/err.log
tar -g $BK_HOME/snapshot -zcvpf $BK_HOME/image`date +%Y%m%d`_full_$RANDOM.tar.gz /home/web/media /dev/null 2>&1
fi
fi
注意:红颜色标出的变量即可生成随机数
增量备份命名使用时间点:touch test`date +%Y.%m.%d_%H:%M:%S`
阅读(2951) | 评论(0) | 转发(0) |