- 论坛徽章:
- 2
|
代码如下:
import os,re,datetime
from os.path import basename,getmtime,getsize
DIR="/home/data/backup/full"
def compare(x, y):
stat_x = os.stat(DIR + "/" + x)
stat_y = os.stat(DIR + "/" + y)
if stat_x.st_ctime < stat_y.st_ctime:
return -1
elif stat_x.st_ctime > stat_y.st_ctime:
return 1
else:
return 0
list = os.listdir(DIR)
list.sort(compare)
f = open("/tmp/backupinfo.report", 'w+')
for e in list:
if re.findall(r'tar.gz',e) :
print >>f,'%s -> %s -> %sMB' % (basename(e),datetime.datetime.fromtimestamp(os.stat(e).st_mtime).strftime('%Y-%m-%d %H:%M'),getsize(e)/1048576)
f.close() |
|