From 86c21fd8a87f6005bebdb6a34535ea217d5a2f45 Mon Sep 17 00:00:00 2001 From: dilokomi Date: Thu, 12 Nov 2026 17:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=99=E6=97=B6=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D=E9=80=82=E9=85=8D,=E5=9B=A0=E4=B8=BA3.14python?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ------------- README_en.md | 14 ------------- quick_backup_multi/__init__.py | 36 ++++------------------------------ quick_backup_multi/config.py | 1 - 4 files changed, 4 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 164b03f..9e8cf0f 100644 --- a/README.md +++ b/README.md @@ -110,20 +110,6 @@ mcd_root/ 是否在备份时临时关闭自动保存 -### enable_copy_file_range - -默认值: `false` - -使用 `os.copy_file_range` 进行文件的复制 - -在某些文件系统中,它会使用基于写时复制(copy-on-write)的 reflink 技术,从而极大地提升复制速度 - -需求: - -- Linux 平台 -- Python >= 3.8 -- 选项 `backup_format` 为 `plain` - ### concurrent_copy_workers 默认值:`0` diff --git a/README_en.md b/README_en.md index 1fe9268..6ee451f 100644 --- a/README_en.md +++ b/README_en.md @@ -110,20 +110,6 @@ Default: `true` If turn off auto save when making backup or not -### enable_copy_file_range - -Default: `false` - -Use `os.copy_file_range` for file copying - -In some file system, it will use the copy-on-write based reflink technique to greatly accelerate the copy speed - -Requirements: - -- Linux -- Python >= 3.8 -- Option `backup_format` set to `plain` - ### concurrent_copy_workers Default: `0` diff --git a/quick_backup_multi/__init__.py b/quick_backup_multi/__init__.py index 325c877..0d3164b 100644 --- a/quick_backup_multi/__init__.py +++ b/quick_backup_multi/__init__.py @@ -84,38 +84,10 @@ def get_backup_file_name(backup_format: BackupFormat): return backup_format.get_file_name('backup') -COPY_FILE_RANGE_SUPPORTED = hasattr(os, 'copy_file_range') -COPY_FILE_RANGE_BUFFER_SIZE = 2 ** 30 # 1GiB - - -def copy_file_fast(src_path: str, dst_path: str) -> str: - """ - A ``shutil.copy2`` alternative that uses ``os.copy_file_range`` whenever possible - - ``os.copy_file_range`` may support copy-on-write, which is much faster than regular copy - """ - if not COPY_FILE_RANGE_SUPPORTED or not config.enable_copy_file_range: - return shutil.copy2(src_path, dst_path) - - if os.path.isdir(dst_path): # ref: shutil.copy2 - dst_path = os.path.join(dst_path, os.path.basename(src_path)) - - try: - with open(src_path, 'rb') as f_src, open(dst_path, 'wb+') as f_dst: - while os.copy_file_range(f_src.fileno(), f_dst.fileno(), COPY_FILE_RANGE_BUFFER_SIZE): - pass - except Exception as e: - server_inst.logger.warning('copy_file_range {} -> {} failed ({}), retrying with shutil.copy'.format(src_path, dst_path, e)) - shutil.copy(src_path, dst_path) - - shutil.copystat(src_path, dst_path) # ref: shutil.copy2 - return dst_path - - -def copy_tree_fast(src_path: str, dst_path: str, ignore=None, copy_function: Callable[[str, str], object] = shutil.copy2): +def copy_tree_fast(src_path: str, dst_path: str, ignore=None): def do_copy(src: str, dst: str): try: - copy_function(src, dst) + shutil.copy2(src, dst) except Exception as e: server_inst.logger.error('Failed to copy file from {} to {}: {}'.format(src, dst, e)) raise @@ -155,12 +127,12 @@ def copy_worlds(src: str, dst: str, intent: CopyWorldIntent, *, backup_format: O server_inst.logger.info('copying {} -> {}'.format(src_path, dst_path)) if os.path.isdir(src_path): - copy_tree_fast(src_path, dst_path, ignore=lambda path, files: set(filter(config.is_file_ignored, files)), copy_function=copy_file_fast) + copy_tree_fast(src_path, dst_path, ignore=lambda path, files: set(filter(config.is_file_ignored, files))) elif os.path.isfile(src_path): dst_dir = os.path.dirname(dst_path) if not os.path.isdir(dst_dir): os.makedirs(dst_dir) - copy_file_fast(src_path, dst_path) + shutil.copy2(src_path, dst_path) else: server_inst.logger.warning('{} does not exist while copying ({} -> {})'.format(src_path, src_path, dst_path)) elif backup_format in [BackupFormat.tar, BackupFormat.tar_gz, BackupFormat.tar_xz]: diff --git a/quick_backup_multi/config.py b/quick_backup_multi/config.py index af83efe..a5a829b 100644 --- a/quick_backup_multi/config.py +++ b/quick_backup_multi/config.py @@ -10,7 +10,6 @@ class SlotInfo(Serializable): class Configuration(Serializable): size_display: bool = True turn_off_auto_save: bool = True - enable_copy_file_range: bool = False concurrent_copy_workers: int = 0 ignored_files: List[str] = [ 'session.lock'