TISUnion / QuickBackupM

A backup / restore plugin, with multiple backup slots
GNU General Public License v3.0
147 stars 20 forks source link

Reflink(Copy On Write)支持 #38

Closed tksmly closed 1 year ago

tksmly commented 1 year ago

https://btrfs.readthedocs.io/en/latest/Reflink.html https://docs.python.org/dev/library/os.html#os.copy_file_range 对btrfs,xfs,zfs等支持cow的文件系统可以大幅度缩短复制时间 https://docs.python.org/zh-cn/3/library/shutil.html#shutil.copy 似乎shutil.copy并不支持这一特性

在我的存档中,cp -r --reflink耗时不到1s,而cp -r --reflink=never需要60s左右

tksmly commented 1 year ago
def cpcow(src_path, dst_path):
    if os.path.isfile(src_path):
        f11 = open(src_path,'r')
        f1 = f11.fileno()
        f21 = open(dst_path,'w+')
        f2 = f21.fileno()
        os.copy_file_range(f1, f2, os.path.getsize(src_path))
    elif os.path.isdir(src_path):
        os.makedirs(dst_path)
        for ww in os.listdir(src_path):
            cpcow(src_path+ "/" + ww,dst_path + "/" +ww)

t1 = time.time()
cpcow("/home/tksmly/Downloads/world", "./ww")
print(time.time() - t1)

没有原生的目录复制 大概长这样?

tksmly commented 1 year ago

https://github.com/TISUnion/QuickBackupM/pull/39

Fallen-Breath commented 1 year ago

closed as the PR is merged