简体   繁体   English

Rsync使用find命令删除原始文件,用符号链接替换原文

[英]Rsync using find command, delete original, replace original with symlink

I work for a graphics company, and our clients submit massive amounts of data. 我在一家图形公司工作,我们的客户提交大量数据。 A single project folder can take up hundreds of gigabytes of space on our server. 单个项目文件夹可能占用我们服务器上数百GB的空间。 While space on my direct attached RAID is limited to 10TB, I have a 96TB storage server connected to my main server via iSCSI. 虽然我的直接连接RAID上的空间限制为10TB,但我有一个96TB存储服务器通过iSCSI连接到我的主服务器。

I'm not versed enough in BASH scripting to automate this process, but what I do manually is perform a find with this command: 我不太熟悉BASH脚本来自动执行此过程,但我手动执行的操作是使用此命令执行查找:

find /disk -type d -name 09\ Client-Files | sed 's/ /\\ /g' > client-origs.txt

From this list I rsync the "09 Client-Files" directory to the storage server using: 从此列表中,我使用以下命令将“09 Client-Files”目录rsync到存储服务器:

rsync -avR /disk/Client-Jobs/1234\ Client/09\ Client-Files /iscsi

With the -R option it's copying the relative path to /iscsi. 使用-R选项,它将相对路径复制到/ iscsi。

After this the original "09 Client-Files" directory is deleted and a symlink pointing to its new location on the /iscsi volume. 在此之后,原始的“09 Client-Files”目录被删除,并且符号链接指向/ iscsi卷上的新位置。

What I'm shooting for is to use the found path as a variable to do everything at once. 我正在拍摄的是使用找到的路径作为变量来一次完成所有事情。 I'm really at a loss on how to proceed. 我真的不知道如何继续。 I've been trying to educate myself on bash variables for days now — I can get them to work on simpler things but in this case I'm coming up empty. 我一直试图在bash变量上自我教育几天 - 我可以让他们在更简单的事情上工作,但在这种情况下,我是空的。 Can you help a brother out? 你能帮助一个兄弟吗?

have you looked at the lndir command? 你看过lndir命令吗? (may need to be installed separately) (可能需要单独安装)

It creates a shadow directory of symbolic links pointing to another directory tree. 它创建一个指向另一个目录树的符号链接的影子目录。

You can do all that at once with find: 您可以使用find一次完成所有操作:

find /usr -type d -name My\ Files -exec rsync -avR '{}' /iscsi \;

For more info man find , right before the end there are several examples. 欲了解更多信息, man find ,在结束之前有几个例子。 Alternatively you can pipe the results using the xargs utility. 或者,您可以使用xargs实用程序来管道结果。

You should explore your manuals more througly, there is a lot of treasure to be found. 你应该更仔细地探索你的手册,有很多宝藏可以找到。

On a bash script you could also put: 在bash脚本上你也可以放:

export MIVARIABLE=$(find /usr -type d -name My\ files)

and then 接着

for i in $MIVARIABLE ;do
   rsync -avR $i /iscsi;
done

But this has drawbacks among them if your results are very big, it may exceed bash maximum text space available for a variable , and if the retrieved names include spaces, some utilities may go crazy. 但是如果你的结果非常大,它可能会超过变量可用的bash最大文本空间,如果检索到的名称包含空格,那么它们就会有一些缺点,一些实用程序可能会变得疯狂。

In a modern system the maximum size on a bash environment variable can be from 8kib to nearly 2MiB, if you put to much info on a variable you'll get a Argument list too long error. 在现代系统中,bash环境变量的最大大小可以从8kib到接近2MiB,如果你在变量上放了很多信息,你会得到一个Argument list too long错误。

So if you need to iterate over a file/directory list you better use find built-in functions or in cooperation with xargs . 因此,如果您需要遍历文件/目录列表,最好使用find内置函数或与xargs合作。 Read carefully their manuals and try some dry runs using echo your_command_line instead, so you gain appropiate experience and confidence with the utilities. 仔细阅读他们的手册,并使用echo your_command_line尝试一些干运行,这样您就可以获得适当的经验和对实用程序的信心。 Look for the -print0 function on find as well as the -0 command on xargs which are designed to avoid some problems with filenames with spaces and symbols in their names. 查找-print0的功能find还有-0的命令xargs其目的是为了避免一些问题,在其名称中空格和符号的文件名。

EDIT: find will handle white spaces correctly with the -exec operator: 编辑: find将使用-exec运算符正确处理空格:

find /usr -type d -name My\ Files -exec rsync -avR '{}' /iscsi \;  -exec rm -rf '{}'\;

would do what you need one after the other. 会一个接一个地做你需要的。 I was pointing out options, so you could decide what was better suited to your needs, I did not meant to confuse you. 我指出了选项,所以你可以决定什么更适合你的需求,我并不想让你迷惑。

Edit2: EDIT2:

find /usr -type d -name 'My Files' -exec rsync -avR '{}' /iscsi \;  -exec rm -rf '{}'\;

funciona igual que el ejemplo de arriba. funciona igual que el ejemplo de arriba。 Cuando bash lee 'My Files' it takes the whole word togheter and does not treat the white spaces inside differently Cuando bash lee'My Files'它需要整个单词,而不是以不同方式处理内部的空白区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM