zoukankan      html  css  js  c++  java
  • 自动备份站点

    PHP网站需要备份,代码如下

    #!/usr/local/anaconda3/bin/python
    # coding:utf-8
    
    # ====================================================
    # Author: chang - EMail:changbo@hmg100.com
    # Last modified: 2018-02-22
    # Filename: zbsitebak.py
    # Description: version update ,base paramiko, sys, time
    # blog:http://www.cnblogs.com/changbo
    # ====================================================
    
    
    import os
    import subprocess
    import time
    import logging
    import shutil
    
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                        datefmt='%a, %d %b %Y %H:%M:%S',
                        filename='zbsitebak.log',
                        filemode='a')
    
    nowDay = time.strftime("%Y%m%d", time.localtime())
    path = os.getcwd()
    blackDir = ['images', 'bdimages']
    # count = 0
    siteBakDir = '/home/sitebakdir/'
    sites = '/home/wwwroot/default/xxx/'
    siteDirs = (((subprocess.Popen("/usr/bin/ls " + sites, shell=True, stdout=subprocess.PIPE)).stdout.read()).decode()).strip()
    
    if not os.path.isdir(siteBakDir):
        os.mkdir(siteBakDir)
    
    for siteDir in siteDirs.split('
    '):
        if os.path.isdir(sites + siteDir) and siteDir != 'default':
            sourceDir = sites + siteDir + '/public_html/'
            destDir = siteBakDir + siteDir + '/public_html/'
            os.system('/usr/bin/mkdir -p ' + destDir)
            files = (((subprocess.Popen("/usr/bin/ls " + sourceDir, shell=True,
                                        stdout=subprocess.PIPE)).stdout.read()).decode()).strip()
            for copyfile in files.split('
    '):
                if copyfile not in blackDir:
                    os.system('/usr/bin/cp -rf ' + sourceDir + copyfile + ' ' + destDir)
            os.system('cd /home/sitebakdir && tar czf /home/allbak/sitebak/' + siteDir + nowDay + '.tar.gz ' + siteDir)
        logging.debug('copy %s files to bak dir...' % siteDir)
    
    os.system('/usr/bin/cp -rf ' + sites + 'default ' + siteBakDir)
    logging.debug('copy default to bak dir...')
    time.sleep(5)
    logging.debug("begin to tar site bak dir")
    os.system('cd /home/sitebakdir && tar czf /home/allbak/sitebak/default' + nowDay + '.tar.gz default')
    logging.debug("bak success!")
    time.sleep(5)
    shutil.rmtree(siteBakDir)
    # for root, dirs, files in os.walk(path):
    #     for each in files:
    #         count += 1
    #     if len(dirs) > 0:
    #         print(dirs)
    # print(path, count, dirs)

    END!

  • 相关阅读:
    python shellcod加载器修改特征值
    python shellcode 分析二
    python shellcode分析
    Hadoop综合大作业1
    Hadoop综合大作业
    分布式文件系统HDFS
    安装Hadoop
    爬虫综合大作业
    爬取全部的校园新闻
    理解爬虫原理
  • 原文地址:https://www.cnblogs.com/changbo/p/8463098.html
Copyright © 2011-2022 走看看