pyhont备份php代码脚本

Posted 梦徒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyhont备份php代码脚本相关的知识,希望对你有一定的参考价值。

#!/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代码脚本的主要内容,如果未能解决你的问题,请参考以下文章

网络工程师的Pyhont实战

Pyhont 高阶函数

一个PHP文件备份脚本

使用PHP脚本备份具有3个月大的数据的特定表

Eclipse 中的通用代码片段或模板

超级有用的9个PHP代码片段