#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import subprocess
import datetime,time
import sys
import tarfile
src_dir = 'svn'
dst_dir = '/data/backup/'
flname = datetime.date.today().isoformat()
now = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
def writelog(status):
f = open("/data/backup.log","a")
f.write('\n'+now)
f.write(status)
f.close()
def compressing():
tar = tarfile.open(dst_dir+flname+'.bz2','w|bz2')
tar.add(src_dir)
tar.close()
writelog(" Compressing file.....")
def deloldfile():
subprocess.call("find /data/backup/ -mtime +30 | xargs rm -f",shell=True)
writelog(" Delete the old file......")
def main():
os.chdir("/data")
compressing()
deloldfile()
if __name__ == '__main__':
main()
阅读(1029) | 评论(0) | 转发(1) |