此脚本适用于备份指定发布目录下的目录,可适当修改运用!
#!/usr/bin/env python #backup app python script. import os import time import sys
nowTime = time.strftime("%Y%m%d")
sourcePath = '/home/zcb/resin-4.0.10/apps/' backupPath = '/home/zcb/tmp/bak' nowTime
if not os.path.exists('/home/zcb/tmp/bak' nowTime): os.mkdir('/home/zcb/tmp/bak' nowTime) print time.strftime("%Y-%m-%d") ' Backup Directory create successfully!'
applist = [] def getAppList(): all = os.listdir(sourcePath) for i in all: if os.path.isdir(sourcePath i): applist.append(i)
def backup_all(): print "%s App Backuping...." % time.strftime("%Y-%m-%d") print "-" * 35 for appName in applist: os.chdir(sourcePath) tar_command = 'tar -zcf %s/%s.tar.gz %s' % (backupPath,appName,appName) if os.system(tar_command) == 0: print "