AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1498113
Accepted
miguelmorin
miguelmorin
Asked: 2019-11-02 06:33:48 +0800 CST2019-11-02 06:33:48 +0800 CST 2019-11-02 06:33:48 +0800 CST

Rsync 没有删除文件并抱怨“设备上没有剩余空间 (28)”

  • 772

我rsync在 macOS 10.14.6 (Mojave) 上使用(2.6.9,协议版本 29)来备份包含视频的磁盘。源有 999GB 容量,75GB 可用,备份有 1TB 容量。命令是:

$ rsync -avxW --progress /Volumes/Video/ /Volumes/Video\ backup/
building file list ... 
40989 files to consider
.DS_Store
       26628 100%    0.00kB/s    0:00:00 (xfer#1, to-check=40987/40989)
.DocumentRevisions-V100/
.Spotlight-V100/
rsync: failed to set times on "/Volumes/Video backup/.Spotlight-V100": Operation not permitted (1)
.fseventsd/
iMovie Library.imovielibrary/movie/Original Media/
iMovie Library.imovielibrary/movie/Original Media/DSC_0004.mov
rsync: writefd_unbuffered failed to write 32768 bytes [sender]: Broken pipe (32)
rsync: write failed on "/Volumes/Video backup/iMovie Library.imovielibrary/movie/Original Media/DSC_0004.mov": No space left on device (28)
rsync error: error in file IO (code 11) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/receiver.c(268) [receiver=2.6.9]
rsync: connection unexpectedly closed (76 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/io.c(453) [sender=2.6.9]

备份磁盘已满,因为rsync没有删除几个现在从原始文件中丢失的文件。我检查了该选项--delete-before是否为默认选项,并且我还尝试--delete删除无关文件,但使用同一文件时遇到了相同的错误。

如何制作完美的磁盘克隆rsync?

video mac
  • 1 1 个回答
  • 489 Views

1 个回答

  • Voted
  1. Best Answer
    miguelmorin
    2019-11-18T14:01:22+08:002019-11-18T14:01:22+08:00

    由于缺乏一个简洁的解决方案,我用 Python 编写了一个 hack 来遍历目标并删除源中不存在的文件和目录。

    确保您不会意外交换源和目标,否则您将丢失原始文件。顺序同rsync:先源后目标。

    默认情况下,代码会在删除前五个路径之前提示确认,因此您可以验证您没有删除源。它删除目标中作为源中符号链接的文件。

    用于:

    python3 rsync_pre_process.py /Volumes/source /Volumes/target
    

    然后您可以运行rsync,例如如下(并-a保留符号链接):

    rsync -avxW --delete --delete-before --progress /Volumes/source /Volumes/target
    

    这是代码rsync_pre_process.py:

    #!/usr/bin/env python3
    # 
    # Usage: python3 rsync_pre_process.py /Volumes/source /Volumes/target [5]
    #
    # You can then run: rsync -avxW --delete --delete-before --progress /Volumes/source /Volumes/target
    # 
    # This code deletes files present in the target that are missing from the
    # source. It circumvents one case of rsync's error "No space left on device
    # (28)" even though you may run rsync with `-delete` and `--delete-before`.
    #
    # It prompts for confirmation to delete a certain number of files or
    # directories, 5 by default, before deleting files without confirmation.
    #
    # It removes files in the target that are symlinks in the source.
    #
    # author: Miguel Morin
    # copyright: public domain
    # year: 2019
    
    import os
    import pathlib
    import shutil
    import sys
    
    MAX_VERIFICATIONS = 5
    
    def remove(path, verify):
        """Removes a file or directory, asking for confirmation first if requested."""
        if verify:
            print(path)
            print("Remove this file? Press RET to proceed, C-c to abort.")
            sys.stdin.read(1)
        p = pathlib.Path(path)
        if os.path.islink(path) or not p.is_dir():
            os.remove(path)
        else:
            try:
                # shutil.rmtree instead of os.remove() because the former works in
                # iMovie folders where the latter throws an error, `PermissionError:
                # [Errno 1] Operation not permitted:`
                shutil.rmtree(path)
            except PermissionError as e:
                print("Unable to remove '%s' due to permission error" % path)
    
    def cleanup(source, target, max_verifications):
        """Deletes all files from the target that are missing from the source, prompting 
        confirmations up to `max_verifications`.
        """
        num_verifications = 0
        for root, dirs, files in os.walk(target, topdown = False):
            for name in files + dirs:
                verify = num_verifications < max_verifications
                target_filepath = os.path.join(root, name)
                source_filepath = target_filepath.replace(target, source)
                if not os.path.exists(source_filepath) or os.path.islink(source_filepath):
                    remove(target_filepath, verify)
                    num_verifications += 1
    
    def main():
        source = sys.argv[1]
        target = sys.argv[2]
    
        if not (source and target):
            raise ValueError("You must supply source and target arguments. Your arguments: " + str(argv[1:]))
    
        if 4 == len(sys.argv):
            max_verifications = int(sys.argv[3])
        else:
            max_verifications = MAX_VERIFICATIONS
    
        cleanup(source = source, target = target, max_verifications = max_verifications)
    
    if "__main__" == __name__:
        main()
    
    • 0

相关问题

  • 命令行将以逗号分隔的值放在单独的行中

  • 当我没有 root 访问权限时,如何在 mac 上安装新的键盘布局?

  • OBS Studio—'无法打开 NVENC 编解码器:功能未实现'

  • 如何用ffmpeg 2.0.2保存TS视频流?

  • 压缩视频可以解码回未压缩的原始格式吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve