为什么要做这个工具

  之前做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

3. 将第一步复制的文件,上传到服务器

  服务器版本升级so easy

文件和一些参数说明

1. 确保系统安装了python(windows 和linux 都支持)

2 .get_upload_files.py

  获取需要上传到服务器上的文件列表,并保存到指定的文件夹

源文件的目录

   fromdir = "source_folder"

根据filelist.txt 复制的文件存储目录

  todir = "backup"

需要上传服务器的文件列表

  filename = 'filelist.txt'

3.backup_server_files.py

备份目录文件

  todir = "backup"

需要备份的文件列表

 filename = 'filelist.txt'
服务器的代码路径,记住最后的 / 需要保留
 SRC_FOLDER = ‘/path_to_server_src_folder/‘

4.filelist.txt 这个文件存储需要上传的文件

git如何获取需要上传的文件
  git diff --name-status HEAD~2 HEAD~3
git diff
git diff b45ba47d1b297217e3ec6a3ab0f61716a8d6ecbc c244d0bf06d56ec86aaedeefa5dcd84dd9febc60
一般来说,通过 hash 串的前 4~6 位就可以区分,所示可以简写为:
git diff b45b 355e

  

git diff这个命令能比较两个提交之间的差异,使用–name-only参数可以只显示文件名。例如:

$ git diff 608e120 4abe32e --name-only
 

php服务器版本更新工具up2server的更多相关文章

  1. 无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它

    无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer.Windows服务器管理工具或NET START命令启动它 1. ...

  2. 新一代服务器性能测试工具Gatling

    新一代服务器性能测试工具Gatlinghttp://automationqa.com/forum.php?mod=viewthread&tid=2898&fromuid=2

  3. windows10 专业版的远程服务器管理工具下载

    一.安装远程服务器管理工具: 下载地址: https://www.microsoft.com/zh-cn/download/details.aspx?id=45520 二.关闭远程服务器管理工具: 1 ...

  4. Linux可视化服务器管理工具webmin

    webmin是一个可视化的linux服务器管理工具,可以帮助我们实现很多功能. Webmin官网: http://www.webmin.com/ 下载地址:http://prdownloads.sou ...

  5. Gatling新一代压力测试工具,新一代服务器性能测试工具Gatling

    Gatling新一代压力测试工具新一代服务器性能测试工具Gatlinghttp://www.infoq.com/cn/articles/new-generation-server-testing-to ...

  6. Web界面的服务器监测工具(转载)

    企业服务器对于企业业务持续性意义重大,系统管理员需要密切关注企业服务器以确保一切正常运行.当发现问题的时候,他们需要知道问题开始出现时的状况,因此调查可以重点放在问题出现的时候,这就意味着定期记录信息 ...

  7. DELL服务器管理工具和RACADM介绍

    DELL服务器管理工具和RACADM介绍 一.Dell服务器管理工具介绍 Dell对服务器(DELL PowerEdge)的管理主要提供了三种管理工具,分别是Dell Remote Access Co ...

  8. [转帖]服务器备份工具:Amanda,Bakula,Clonezilla,Rsnapshot,Mondo Rescue

    服务器备份工具:Amanda,Bakula,Clonezilla,Rsnapshot,Mondo Rescue https://ywnz.com/linuxyffq/5270.html 改天试用一下. ...

  9. (视频) 基于HTML5的服务器远程访问工具

    现在云计算这么发达,基本上每个人都多少有几台Windows或者Linux服务器运行在云端,要直接进入这些服务器进行配置就需要使用类似远程桌面或者Putty这类的工具,虽然大多数Windows电脑都自带 ...

随机推荐

  1. C语言中两位ASCII码可以表示汉字

    最近偶然有人问到这个相关字符编码的问题,所以百度了下参考了这两个资料,进行了简单分析. ******************************************************** ...

  2. Windows Azure Cloud Service (47) 修改Cloud Service时区

    <Windows Azure Platform 系列文章目录> 本文介绍内容适合于Azure Global和Azure China 我们在使用Cloud Service的时候,会发现默认的 ...

  3. JAVA - Collections用法总结

    一生二,二生三,三生万物,基础永远是一个计算机人的立身之本.数据结构这门课程的分析奠定了工程师对各种平台中的容器类,集合类的理解基础,正如好多人所说的,如果你对某个平台的集合类理解的不透彻,很可能,你 ...

  4. 策略模式(Stategy Pattern)

    知识点 找出引用中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起. 针对接口编程,而不是实现编程. 多用组合,少用继承 示例

  5. EF 中事务的书写

    在EF 中怎么使用事务? 这个问题纠结了我好久,直到有人跟我一起讨论,我和同事一起讨论查资料. 查的好多资料都是使用 using (TransactionScope scope = new Trans ...

  6. C# Winform MD5加密学习积累

    string password = txtPassword.Text.Trim(); byte[] result = Encoding.Default.GetBytes(password); MD5 ...

  7. MFC文件操作

    文件操作:二进制文件和文本文件的区别.二进制文件将数据在内存中存在的模式原封不动的搬到文件中,而文本文件是将数据的asc码搬到文件中.首先做一个读写文件的菜单,在CxxView里响应1.C的方式:fw ...

  8. $("").click与onclick的区别示例介绍

    Html代码: <script type="text/javascript"> $(function(){ $("#btn4").click(fun ...

  9. jquery简单原则器(匹配索引大于指定值的元素)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 点我吧工作总结(技术篇) Cobar原理和环境搭建

    我思故我在,提问启迪思考! 1.什么是Cobar? Cobar是关系型数据的分布式处理系统,它可以在分布式的环境下看上去像传统数据库一样为您提供海量数据服务.cobar已经在阿里巴巴B2B公司稳定运行 ...