现在的位置: 首页 > Linux > unix > 正文
unix下find打包不全问题解决
2014年01月03日 unix ⁄ 共 1929字 暂无评论 ⁄ 被围观 3,901 views+

为了对DB2的日志进行归档,方便以后进行即时点恢复,写了一个脚本进行归档压缩,打包命令主要部分如下:

find /db2/PRD/log_archive/db2prd/PRD/NODE0000/C0000000  -ctime +4 |xargs tar –cf /backup/db_logbak_`date "+%Y%m%d"`.tar

该命令目的是查找4天前的DB2日志,进行归档,但实际发现归档的文件不全,智能归档部分文件,网上找了很多资料,也看了慢帮助,发现其他人也有此问题,却没人提出一个好的解决办法。测试了如下几种情况:

find /db2/PRD/log_archive/db2prd/PRD/NODE0000/C0000000  -ctime +4 |xargs tar -rf /backup/db_logbak_`date "+%Y%m%d"`.tar

用r参数进行追加打包,但需要提前创建。

用-exec传递查找到的内容,发现也不可行。

hp-ux下,tar没有-T参数,看来似乎无法完成。但问题总要解决,于是翻遍了Google,终于在某个角落看到了如下这样一种写法,于是所有问题都迎刃而解:

tar -cf  /backup/db_logbak_`date "+%Y%m%d"`.tar `find /db2/PRD/log_archive/db2prd/PRD/NODE0000/C0000000  -ctime +4`

看到没?tar放到前面去了。。。多巧妙的方法啊,自己怎么就想不到呢?

整个脚本如下(写点有点复杂,但由于服务器较多,为了方便对备份进行监控和查看,就写了很多判断和日志):

#!/usr/bin/sh
K=7
DATADIR=/db2/PRD/log_archive/db2prd/PRD/NODE0000/C0000000
BAKDIR=/dp_backup/log
DATANAME=prd_log
TODAY=`date "+%Y%m%d"`

[ -d $BAKDIR ] ||  mkdir -p  $BAKDIR
echo "`date +%T`: starting tar the log...">> $BAKDIR/$TODAY.bak.log
tar -cf $BAKDIR/$DATANAME-$TODAY.tar `find $DATADIR  -ctime +4`
if [ $? -eq 0 ];then
echo "`date +%T`: $TODAY tar  is successfull!" >> $BAKDIR/$TODAY.bak.log
else
echo "`date +%T`: $TODAY tar is error!" >> $BAKDIR/$TODAY.bak.log
exit 3
fi

echo "`date +%T`: starting del the $DATANAME log...">> $BAKDIR/$TODAY.bak.log
find $DATADIR -ctime +4 | xargs rm -f
if [ $? -eq 0  ];then
echo "`date +%T`: del the $datanem log  is successful!" >> $BAKDIR/$TODAY.bak.log
else
echo "`date +%T`:del the $datanem log is error!" >> $BAKDIR/$TODAY.bak.log
exit 4
fi

echo "`date +%T`: starting gzip the tar log...">> $BAKDIR/$TODAY.bak.log
/usr/contrib/bin/gzip  $BAKDIR/$DATANAME-$TODAY.tar
if [ $? -eq 0 ];then
echo "`date +%T`: $TODAY gzip  is successful!" >> $BAKDIR/$TODAY.bak.log
else
echo "`date +%T`: $TODAY gzip is error!" >> $BAKDIR/$TODAY.bak.log
exit 5
fi
echo "`date +%T`: starting del the tar log...">> $BAKDIR/$TODAY.bak.log
#del the bak
find $BAKDIR -ctime +$K | xargs rm -f
if [ $? -eq 0 ];then
echo "`date +%T`: del $K day bak  is successful!" >> $BAKDIR/$TODAY.bak.log
"/dp_backup/tarlog.sh" 45 lines, 1448 characters

else
echo "`date +%T`: del $K day bak  is error!" >> $BAKDIR/$TODAY.bak.log
exit 6
fi
exit

 

给我留言

留言无头像?


×