Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2814206
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: LINUX

2012-05-11 12:15:53

#!/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
##添加蓝色字体即可正常!

阅读(926) | 评论(0) | 转发(1) |
0

上一篇:ntpdate.sh

下一篇:rsync备份shell

给主人留下些什么吧!~~