Rsync - Splitt 文件夹/子文件夹结构

Rsync - Splitt 文件夹/子文件夹结构

我使用 openmediavault(OMV 是来自 openmediavault.org 的 NAS 软件)并定义了不同的共享。在其中一个共享中,我有一个如下所示的文件夹结构:(示例)

Subfolder"ABC"/Subsubfolder"SWU"/*.*Files   
Subfolder"ABC"/Subsubfolder"SXY"/*.*Files
Subfolder"ABC"/Subsubfolder"ZWE"/*.*Files   
Subfolder"BCD"/Subsubfolder"SWU"/*.*Files
Subfolder"CDE"/Subsubfolder"ABC"/*.*Files   
Subfolder"TXY"/Subsubfolder"SWU"/*.*Files

并想通过 OMV 内的 rsync 将其分为两个不同的共享,但我在使用 include /exclude 时遇到问题。我使用 rsync 的可能性有限,但 OMV-Rsync gui 中有一个额外的选项字段来输入包含/排除语句。 奥玛维

我想将其拆分在子文件夹中,我希望子文件夹从“0”到“Sj”作为一部分,另一部分从“Sk”到“Z”开始。

我已经尝试过了

--exclude={/S[k-z]*/,/[T-z]*/} 

但这并没有按预期工作。试运行显示,例如文件夹中的文件:Zur/S056776/ 也已同步 我能做什么,才能正确执行?

答案1

编辑后的答案以匹配编辑后的问题

您可以尝试以下排除模式。将目录更改为公用文件夹上方并修改模式以folder匹配您的实际公用文件夹名称。

--exclude={/folder/S[k-z]*/,/folder/[T-z]*/}

我不知道为什么您尝试的模式不起作用(但如果您确切地显示哪些目录不起作用,我也许可以帮助您找到问题),

--exclude={/S[k-z]*/,/[T-z]*/}

编辑2,3 - NAS服务器运行Linux操作系统

NAS服务器运行Linux操作系统。我已经下载了openmediavault、OMV并进行了测试。它正在运行ssh服务器,并且可以运行rsync以在计算机和服务器之间传输文件以及通过远程登录到服务器并在服务器内部ssh运行。rsync

  • 登录信息除非您已更改

网页界面

User: admin
Password: openmediavault

客户端(SSH、控制台)

User: root
Password: <The password that you have set during installation>
  • 打开终端窗口并通过以下方式连接ssh

    ssh root@ip-address-to-your-server
    # example: ssh [email protected]  # if local
    
  • 登录或使用密钥认证rsync在服务器中运行

  • 在服务器中运行命令

    cd 'path-to-directory-above-folder'
    
    mkdir target1  # only once, or use a target above your current directory
    mkdir target2  #               -"-
    
    rsync -Havn --exclude={/target*/,/folder/S[k-z]*/,/folder/[T-z]*/} * target1
    rsync -Havn --exclude={/target*/,/folder/[0-R]*/,/folder/S[0-j]*/} * target2
    
  • 您可以运行一些其他命令来查看一切正常,例如

    for i in $(find folder);do test -e "${i/folder/target1\/folder}" || test -e "${i/folder/target2\/folder}" || echo "$i not copied";done
    
  • 完成后从服务器注销(在我的例子中从用户myself和从root

    exit
    

    在此输入图像描述

原答案

我不确定,但我思考以下命令行将创建您想要的内容。

在测试目录中,我在几个子目录和文件中创建了子目录target1target2folder、 和用于测试。folder

rsync -Havn --exclude={/target*/,/folder/S[k-z]*/,/folder/[T-z]*/} * target1

rsync -Havn --exclude={/target*/,/folder/[0-R]*/,/folder/S[0-j]*/} * target2
  • 首先使用选项-n“dry run”(如这里所示)运行它们,以检查它们将执行的操作,
  • 然后,(也许在修改后)当他们执行您想要的操作时,删除-n并将rsync目录结构复制到目标目录。

我使用以下目录树进行了测试:

$ find |sort
.
./folder
./folder/ABC
./folder/ABC/SWU
./folder/ABC/SWU/file
./folder/ABC/SXY
./folder/ABC/SXY/file
./folder/ABC/ZWE
./folder/ABC/ZWE/file
./folder/AIB
./folder/AIB/Sja
./folder/AIB/Sja/file
./folder/AIB/Skb
./folder/AIB/Skb/file
./folder/AIB/SWU
./folder/AIB/SWU/file
./folder/BCD
./folder/BCD/SWU
./folder/BCD/SWU/file
./folder/CDE
./folder/CDE/SWU
./folder/CDE/SWU/file
./folder/Sja
./folder/Sja/Skb
./folder/Sja/Skb/file
./folder/Sja/SWU
./folder/Sja/SWU/file
./folder/Skb
./folder/Skb/Sja
./folder/Skb/Sja/file
./folder/Skb/SWU
./folder/Skb/SWU/file
./folder/TXX
./folder/TXX/Sja
./folder/TXX/Sja/file
./folder/TXX/Sjb
./folder/TXX/Sjb/file
./folder/TXX/Skb
./folder/TXX/Skb/file
./folder/TXY
./folder/TXY/SWU
./folder/TXY/SWU/file
./folder/Zab
./folder/Zab/ABC
./folder/Zab/ABC/file
./folder/zBC
./folder/zBC/ABC
./folder/zBC/ABC/file
./folder/zBC/ABC/target
./folder/zBC/target
./target1
./target2

进行以下“试运行”

$ rsync -Havn --exclude={/target*/,/folder/S[k-z]*/,/folder/[T-z]*/} * target1
sending incremental file list
folder/
folder/ABC/
folder/ABC/SWU/
folder/ABC/SWU/file
folder/ABC/SXY/
folder/ABC/SXY/file
folder/ABC/ZWE/
folder/ABC/ZWE/file
folder/AIB/
folder/AIB/SWU/
folder/AIB/SWU/file
folder/AIB/Sja/
folder/AIB/Sja/file
folder/AIB/Skb/
folder/AIB/Skb/file
folder/BCD/
folder/BCD/SWU/
folder/BCD/SWU/file
folder/CDE/
folder/CDE/SWU/
folder/CDE/SWU/file
folder/Sja/
folder/Sja/SWU/
folder/Sja/SWU/file
folder/Sja/Skb/
folder/Sja/Skb/file

sent 742 bytes  received 106 bytes  1,696.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

$ rsync -Havn --exclude={/target*/,/folder/[0-R]*/,/folder/S[0-j]*/} * target2
sending incremental file list
folder/
folder/Skb/
folder/Skb/SWU/
folder/Skb/SWU/file
folder/Skb/Sja/
folder/Skb/Sja/file
folder/TXX/
folder/TXX/Sja/
folder/TXX/Sja/file
folder/TXX/Sjb/
folder/TXX/Sjb/file
folder/TXX/Skb/
folder/TXX/Skb/file
folder/TXY/
folder/TXY/SWU/
folder/TXY/SWU/file
folder/Zab/
folder/Zab/ABC/
folder/Zab/ABC/file
folder/zBC/
folder/zBC/ABC/
folder/zBC/ABC/file
folder/zBC/ABC/target/
folder/zBC/target/

sent 713 bytes  received 100 bytes  1,626.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

相关内容