一、介绍
生产线上有一台bi ftp服务器(用来接受游戏的数据),每个游戏按指定格式上传到以年月日的目录中,如:20170628 这样的目录,每天一个目录,因此数据日积月累导致inode和磁盘空间不断的被消耗,另外有的项目下线,因此这些都需要把这些数据打包归档起来以节省空间;
二、解决方案
使用Bash写了一个小工具只需要填写指定目录,多长日期之前的 两项运行工具,即可对指定目录下指定时间以前的数据进行打包,并在检验打包好后,删除原备份目录。以下是代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/bash
rootdir=
/data1/games/zgws
#需要归档整理的目录
declare
-i Ago=20170301
#指定日期前
cd
$rootdir
for
d
in
$(
ls
):
do
if
[ ! -d $d ];
then
continue
else
set
-i $d
if
[ $d -
le
$Ago ]
then
echo
$d
tar
czvf ${d}.
tar
.gz $d
declare
-i tarhow=$(
tar
tvf ${d}.
tar
.gz |
wc
-l)
#检验归档后的文件个数
declare
-i srchow=$(
ls
$d |
wc
-l)
#原目录中文件个数
let
tarhow=($tarhow -1)
if
[ $tarhow -
eq
$srchow ]
then
echo
"$d tar OK,$d has $srchow files,and belong tared has $tarhow ,time at: $(date +%F-%H-%M-%S)"
>>tarlog.log
#保存检验日志
rm
-r $d
else
echo
"$d tar failed!"
break
fi
fi
fi
done
|
三、使用中用到的问题
可以修改做成定期去执行,主要就是日期问题,但不建议,另外主要是通过目录统一“年月日”格式,其他的不行,要归档的目录中不可以有隐藏文件及.开头的文件,否则会产生检验不通过。
本程序仅供参考,和个人备忘,如有不当之处欢迎指正!
本文转自 dyc2005 51CTO博客,原文链接:http://blog.51cto.com/dyc2005/1942717,如需转载请自行联系原作者