7天内的备份全部保留,7天外的备份只保留3份
格式如下:
/u02/applications/micro-shop-20161117-1650.tgz
/u02/applications/micro-shop-20161124-1446.tgz
/u02/applications/micro-shop-20161208-1847.tgz
/u02/applications/micro-shop-20161222-1337.tgz
/u02/applications/micro-shop-20170105-1527.tgz
/u02/applications/micro-shop-20170112-1501.tgz
/u02/applications/shop-portal-20161222-1349.tgz
/u02/applications/shop-portal-20161223-0206.tgz
/u02/applications/wechat-20150430-1750.tgz
/u02/applications/wechat-20150507-1013.tgz
/u02/applications/wechat-20150507-1514.tgz
/u02/applications/wechat-20150515-1713.tgz
/u02/applications/wechat-20150527-1123.tgz
/u02/applications/wechat-20150604-1337.tgz
#!/bin/sh
find /u02/applications -maxdepth 1 -name "*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9].tgz" -mtime +7 -type f|sort > /tmp/all.txt
cat /tmp/all.txt|awk -F '-[0-9][0-9][0-9][0-9]' '{print $1}'|awk -F '/' '{++S[$4]} END {for(a in S) if(S[a]>3) print a,S[a]-3}' > /tmp/count.txt
while read NAME COUNT
do sed -n "/$NAME-/p" /tmp/all.txt| sed -n "1,$COUNT p">> /tmp/del.txt
done </tmp/count.txt
cat /tmp/del.txt |xargs -n 10 rm -f
cat /dev/null > /tmp/del.txt