Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108437
  • 博文数量: 32
  • 博客积分: 1445
  • 博客等级: 上尉
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-29 13:58
文章分类
文章存档

2014年(3)

2012年(27)

2010年(2)

我的朋友

分类:

2012-10-18 14:21:13

原文地址:backuplog.sh 作者:qingheliu

#!/bin/sh
echo "backup log "
Backup_date=`date +%y%m%d`
cp /usr/local/xncenter/logcenter/apache.log    /usr/local/xncenter/logcenter/apache.log.${Backup_date}
echo "">/usr/local/xncenter/logcenter/apache.log
cd /usr/local/xncenter/logcenter
tar -zcvf apache.log.${Backup_date}.tar.gz   apache.log.${Backup_date} >> /home/liuxiaojie/tar.err 2>&1 
mv   apache.log.${Backup_date}.tar.gz  /backuplog/apachelog/ 
if [ -e /backuplog/apachelog/apache.log.${Backup_date}.tar.gz  ]  ; then
   rm -f /usr/local/logcenter/apache.log.${Backup_date}
   echo "apache.log.${Backup_date} Backup finished"  >>/home/liuxiaojie/logbackup.log                
else
   echo "apache.log.${Backup_date} Backup failed"  >>/home/liuxiaojie/logbackup.log
fi

echo ""  >>/home/liuxiaojie/logbackup.log
echo ""  >>/home/liuxiaojie/logbackup.log
cd  /usr/local/xncenter/logcenter
cp pureftpd.log pureftpd.log.${Backup_date}
echo "">/usr/local/logcenter/pureftpd.log
tar -zcvf pureftpd.log.${Backup_date}.tar.gz  pureftpd.log.${Backup_date} >> /home/liuxiaojie/tar.err 2>&1
mv  pureftpd.log.${Backup_date}.tar.gz   /backuplog/ftplog/
if [ -e /backuplog/ftplog/pureftpd.log.${Backup_date}.tar.gz  ]  ; then
  rm -f /usr/local/logcenter/pureftpd.log.${Backup_date} 
   echo "pureftpd.log.${Backup_date} Backup finished"  >>/home/liuxiaojie/logbackup.log
else
   echo "pureftpd.log.${Backup_date} Backup failed"  >>/home/liuxiaojie/logbackup.log
fi

cp /usr/local/xncenter/logcenter/squid.log    /usr/local/xncenter/logcenter/squid.log.${Backup_date}
echo "">/usr/local/xncenter/logcenter/squid.log
cd /usr/local/xncenter/logcenter
tar -zcvf squid.log.${Backup_date}.tar.gz   squid.log.${Backup_date} >> /home/liuxiaojie/tar.err 2>&1
mv   squid.log.${Backup_date}.tar.gz  /backuplog/squidlog/                 
if [ -e /backuplog/squidlog/squid.log.${Backup_date}.tar.gz  ]  ; then
   rm -f /usr/local/logcenter/squid.log.${Backup_date}
   echo "squid.log.${Backup_date} Backup finished"  >>/home/liuxiaojie/logbackup.log
else
   echo "squid.log.${Backup_date} Backup failed"  >>/home/liuxiaojie/logbackup.log
fi

/bin/sh  /backuplog/put.sh
find    /backuplog/apachelog  -mtime +10 |  xargs rm -rf
find    /backuplog/ftplog     -mtime +10 |  xargs rm -rf
find    /backuplog/squidlog   -mtime +10 |  xargs rm -rf

put.sh内容:
#!/bin/sh
Backup_date=`date +%y%m%d`
ftp -n 10.4.2.246 >error 2>&1 <
user linuxweb linuxweb
bin
prompt
cd /logbackup/61.***.***.164/apachelog
lcd  /backuplog/apachelog
put apache.log.${Backup_date}.tar.gz
cd /logbackup/61.***.***.164/ftplog
lcd  /backuplog/ftplog
put pureftpd.log.${Backup_date}.tar.gz
cd /logbackup/61.***.***.164/squidlog
lcd  /backuplog/squidlog
put squid.log.${Backup_date}.tar.gz
bye
EOC

trouble:
在tar zcvf 使用时遇到一个奇怪的问题, 手动执行命令和脚本(命令写在脚本里面都可以),但是放到cron job里面tar运行不正常,仅仅压缩一半文件(例如:正常压缩有30M,放到cron job里面执行压缩后的文件仅仅有10m左右,但该文件是可以解压的)
解决方法:
tar zcvf  /data/bak/ungeo21dns-${Backup_date}.tar.gz  bind9 > /data/bak/backup.log
##添加蓝色字体即可正常!

阅读(473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~