标签:
之前做php 开发的时候,每次版本更新,要把修改的文件同步到服务器,都要小心翼翼,如果漏掉了文件,那就完蛋了,KPI,奖金什么的都没了。
所以写了这个工具。代码在github https://github.com/foxswang/up2server
1. 复制 获取要上传的文件 运行
python get_upload_file.py
get_upload_file.py的代码如下:
#!/usr/bin/python import os import os.path import shutil import time, datetime import string fromdir = "source_folder" todir = "backup" filename = ‘filelist.txt‘ # def cpFile(srcPath, destPath): shutil.copy(srcPath,destPath) #shutil.copytree(srcPath,destPath) # def copyFiles(sourceDir, targetDir): if sourceDir.find(".svn") > 0: return for file in os.listdir(sourceDir): sourceFile = os.path.join(sourceDir, file) targetFile = os.path.join(targetDir, file) if os.path.isfile(sourceFile): if not os.path.exists(targetDir): os.makedirs(targetDir) if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))): open(targetFile, "wb").write(open(sourceFile, "rb").read()) if os.path.isdir(sourceFile): First_Directory = False copyFiles(sourceFile, targetFile) # if __name__ == "__main__": text_file = open("./"+filename ,"r") #current_path = os.getcwd() current_path = os.getcwd() all_line = 0 folder_count = 0; print("current_path "+ current_path ) if not os.path.exists(os.path.join(current_path, todir) ): os.makedirs(os.path.join(current_path, todir) ) for line in text_file: line=line.strip(‘\n‘) srcFile = current_path + line dstFile = current_path + ‘/‘ + todir + line targetDir = os.path.dirname(dstFile) if not os.path.isfile(srcFile): folder_count = folder_count+1 continue; print (srcFile) print (dstFile) if not os.path.exists(targetDir): os.makedirs(targetDir) print("cp "+ srcFile +" to " + dstFile) cpFile(srcFile,dstFile) all_line = all_line + 1 print ("copy success file : %d folder: %d" % (all_line,folder_count))
2. 备份服务器的文件,方便升级失败后进行恢复:
python backup_server_files.py
服务器版本升级so easy
获取需要上传到服务器上的文件列表,并保存到指定的文件夹
fromdir = "source_folder"
todir = "backup"
filename = ‘filelist.txt‘
todir = "backup"
filename = ‘filelist.txt‘
SRC_FOLDER = ‘/path_to_server_src_folder/‘
git diff --name-status HEAD~2 HEAD~3 git diff git diff b45ba47d1b297217e3ec6a3ab0f61716a8d6ecbc c244d0bf06d56ec86aaedeefa5dcd84dd9febc60 一般来说,通过 hash 串的前 4~6 位就可以区分,所示可以简写为: git diff b45b 355e
http://www.cnblogs.com/QLeelulu/archive/2009/12/09/1619927.html
标签:
原文地址:http://www.cnblogs.com/likwo/p/4805948.html