gpt4 book ai didi

用于部署 : comparing two folders to generate delta files to backup and ftp 的 Python 脚本

转载 作者:行者123 更新时间:2023-11-28 18:07:11 25 4
gpt4 key购买 nike

我正在通过比较两个文件夹(devprodmirror)来生成增量文件,然后备份现有文件并复制到 prodmirror,从而创建用于部署的 python 脚本 文件夹也通过 ftp 增量传输到服务器。

下面是代码..

问题:def difference_dict(Dict_A, Dict_B) 必须只识别 A-B ,但如果文件在 B 中发生更改(即 prodmirror),也必须返回,这里需要一些帮助/指点。

    import os
import hashlib

srcdir = 'C:\dev'
tgtdir = 'C:\prodmirror'

# definition of function to retrieve MD5 using small chunks of file
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname,'rb') as f:
for chunk in iter(lambda: f.read(2 ** 20), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()

# definition of function to find dictionaries difference,i.e present in A not in B
def difference_dict(Dict_A, Dict_B):
output_dict = {}
for key in Dict_A.keys():
if key not in Dict_B.keys():
output_dict[key] = Dict_A[key]
return output_dict

srcdict={}
for path, subdirs, files in os.walk(srcdir):
for filename in files:
f = os.path.join(path, filename)
srcdict[md5(f)]= f

print("SRC Dict :"+str(srcdict))

tgtdict={}
for path, subdirs, files in os.walk(tgtdir):
for filename in files:
f = os.path.join(path, filename)
tgtdict[md5(f)]= f
print("TGT Dict :"+str(tgtdict))


print("DIFF Dict :"+str(difference_dict(srcdict,tgtdict)))

最佳答案

最后,在尝试了一些脚本和网络滞后的同步问题之后,我们选择的最好的免费选择是免费工具 ..winscp,这里是如何创建文档 --> https://winscp.net/eng/docs/task_synchronize_full

我发现能够以二进制模式和自动监视功能在安全协议(protocol)中同步的优点(我们不使用但很好)第一个副本,服务器文件夹复制到本地并启动同步(2 种模式可用,自动/手动)

因此,无论您做什么更改,工具都会与服务器副本进行比较,并只移动更改的文件!

env 我们从 windows 到 linux。

关于用于部署 : comparing two folders to generate delta files to backup and ftp 的 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52879526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com