码迷,mamicode.com
首页 > Web开发 > 详细

pyhont备份php代码脚本

时间:2017-08-04 18:18:00      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:activity   get   hpc   tor   sys   orm   source   class   formatter   

#!/usr/bin/env python
# encoding: utf-8

import time
import os
import sys
import logging

#create logger
logger = logging.getLogger("phpfile")
logger.setLevel(logging.DEBUG)
#create console handler and set level to error
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
#create file handler and set level to debug
fh = logging.FileHandler("phpfile.log")
fh.setLevel(logging.DEBUG)
#create formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
#add formatter to ch and fh
ch.setFormatter(formatter)
fh.setFormatter(formatter)
#add ch and fh to logger
logger.addHandler(ch)
logger.addHandler(fh)

def backup():
    source = [‘/apps/emc_nas/cms/activity‘,‘/apps/emc_nas/cms/phpcms‘]
    #source = [‘/apps/emc_nas/cms/activity‘]
    target_dir = ‘/apps/emc_nas/bak/cms_backup/‘
    today = target_dir + time.strftime(‘%Y%m%d‘)
    now = "phpcms_" + time.strftime(‘%Y%m%d‘)

    
    if not os.path.exists(today):
        os.mkdir(today)
        print ‘Successfully created directory‘, today
    logger.info(today)    
    
    target = today + os.sep + now + ‘.tar.gz‘
    logger.debug(target)
    tar_backup = "tar -zcvf %s %s" % (target,‘ ‘.join(source))
    logger.info(tar_backup)

    if os.system(tar_backup) == 0:
        print "Successful backup to ", target
    else:
        print "Backup FAILED!!"

    logger.debug(tar_backup)
if __name__ == "__main__":
	backup()

 

  

pyhont备份php代码脚本

标签:activity   get   hpc   tor   sys   orm   source   class   formatter   

原文地址:http://www.cnblogs.com/saneri/p/7286367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!