3

服务器日志备份超节省空间的思路

 2 years ago
source link: https://zhang.ge/4104.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
服务器日志备份超节省空间的思路 | 张戈博客
Jager · 7月10日 · 2014年压缩备份 · 远程备份 365次已读

这两天,监控频繁发来服务器磁盘空间90%+的报警,打扰睡觉不说,塞得满满的总是不舒服的。刚来公司才20天,对于部分细节上的运维了解得还不是很到位,比如这备份机制是怎样的?于是,将几台空间老报警的服务器的文件及任务计划仔细看了下,总算是摸清楚了这新公司的重要日志的备份机制了:

由于最终存储备份的2台机器用的是增量同步备份,从而越来越大。而日志要留着以备查验,只好考虑做压缩备份了。

于是把日志来源服务器A、B...N等服务器上的rsync备份脚本修改如下,同步之前先做压缩(8-17行):

#!/bin/bash
client="192.168.1.$1"
project='website'
passwordFile='./password'
src='/data/logs/resin/'
dest="[email protected]::accesslog/$project/$server/"
#Desc compress the rensin's log
begin=`date +%Y-%m-%d-%H:%M`
cd $src
echo ***********Compress start at $begin**************>>compress.log
echo the file list of Compressing this time:>>compress.log
for file in `find . -name "*201[3-9]*" -type f ! -name "*.tar.gz"`;do
tar cvzf $file.tar.gz $file >>compress.log && rm -f $file
echo ***********Compress Completed at `date +%Y-%m-%d-%H:%M`**************>>compress.log
#rsync
cd /data/scripts/accesslog_rsync
rsync -ahrv --delete --delete-excluded --exclude='jvm-default.log*' --exclude='watchdog-manager.log*' --password-file=$passwordFile $src $dest
exit 0

压缩完成之后再进行rsync同步备份。修改后的备份机制如下:

写完脚本,并做好任务计划之后,我开始写脚本压缩日志来源服务器及最终备份服务器上已存在的日志文件。由于这些日志文件都是文本格式,压缩效果非常赞!体积几乎减小了十倍!

下面是一台备份目录做压缩前后的对比截图

压缩前:264G

压缩后:30G

压缩费时:3小时左右。

写在最后:其实这些备份方法在老公司一直都在用的,新公司一直都是由开发人员兼顾运维, 估计也没考虑那么多了吧!文中的脚本非常简单,主要分享了一个服务器日志备份的省空间思路,没啥技术含量,高手勿喷,哈哈!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK