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
    • 最新
    • 标签
主页 / unix / 问题 / 533044
Accepted
openCivilisation
openCivilisation
Asked: 2019-07-31 19:26:17 +0800 CST2019-07-31 19:26:17 +0800 CST 2019-07-31 19:26:17 +0800 CST

只有当它包含与模式匹配的文件时,rsync 才能用于排除整个目录和子内容?

  • 772

我希望通过排除包含“.protect”文件的目录的整个目录和内容,在 linux 中使用 rsync 为我的 NAS 实现大约 20TB 的一些清理功能

我在子文件夹中生成非常大的缓存,例如

缓存/simulation_v001/reallybigfiles_*.bgeo

缓存/simulation_v002/reallybigfiles_*.bgeo

缓存/simulation_v003/reallybigfiles_*.bgeo

如果存在这样的文件-cache/simulation_v002/.protect

然后我想建立一个 rsync 操作将所有文件夹移动到一个临时/回收位置,不包括 cache/simulation_v002/ 及其所有内容。

我以前用 python 做过类似的事情,但我很好奇是否可以使用 rsync 或其他方法简化操作。

rsync archive
  • 1 1 个回答
  • 226 Views

1 个回答

  • Voted
  1. Best Answer
    openCivilisation
    2019-08-05T18:27:20+08:002019-08-05T18:27:20+08:00

    感谢 cas 的提示,我能够创建这个工作流来解决 bash 脚本的问题。它并不理想,因为如果它为更快的操作做了一个动作会更好(我希望 rsync 有这个能力)。该脚本将在当前文件夹下方搜索带有 find 的文件,创建排除列表,然后使用基本卷中的 rsync 将所有其他文件夹移动到垃圾文件夹,保留下面的完整路径,以便可以非破坏性地恢复任何错误。

    如果此解决方案在 git dev 分支中,则链接到当前状态 - https://github.com/firehawkvfx/openfirehawk-houdini-tools/blob/dev/scripts/modules/trashcan.sh

    #!/bin/bash
    
    # trash everything below the current path that does not have a .protect file in
    # the folder.  it should normally only be run from the folder such as
    # 'job/seq/shot/cache' to trash all data below this path.
    
    # see opmenu and firehawk_submit.py for tools to add protect files based on
    # a top net tree for any given hip file.
    
    argument="$1"
    
    echo ""
    ARGS=''
    
    if [[ -z $argument ]] ; then
      echo "DRY RUN. To move files to trash, use argument -m after reviewing the exclude_list.txt and you are sure it lists everything you wish to protect from being moved to the trash."
      echo ""
      ARGS1='--remove-source-files'
      ARGS2='--dry-run'
    else
      case $argument in
        -m|--move)
          echo "MOVING FILES TO TRASH."
          echo ""
          ARGS1='--remove-source-files'
          ARGS2=''
          ;;
        *)
          raise_error "Unknown argument: ${argument}"
          return
          ;;
      esac
    fi
    
    current_dir=$(pwd)
    echo "current dir $current_dir"
    base_dir=$(pwd | cut -d/ -f1-2)
    echo "base_dir $base_dir"
    
    
    source=$(realpath --relative-to=$base_dir $current_dir)/
    echo "source $source"
    target=trash/
    echo "target $target"
    
    # ensure trash exists at base dir.
    mkdir -p $base_dir/$target
    echo ""
    echo "Build exclude_list.txt contents with directories containing .protect files"
    find . -name .protect -print0 |
        while IFS= read -r -d '' line; do
            path=$(realpath --relative-to=. "$line")
            dirname $path
        done > exclude_list.txt
    
    path_to_list=$(realpath --relative-to=. exclude_list.txt)
    echo $path_to_list >> exclude_list.txt
    
    cat exclude_list.txt
    
    cd $base_dir
    
    # run this command from the drive root, eg /prod.
    rsync -a $ARGS1 --prune-empty-dirs --inplace --relative --exclude-from="$current_dir/exclude_list.txt" --include='*' --include='*/' $source $target $ARGS2 -v
    cd $current_dir
    
    • 1

相关问题

  • rsync - 使用 shell 脚本将每个 JPG/jpg 文件从一个硬盘驱动器移动到一个目录

  • tar 目录只发送修改过的文件块

  • 如何复制具有相对重复符号链接的目录树?

  • rsync 排除问题

  • rsync 端口 22 和 873 使用

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve