在终端中,将多个文件夹合并为一个
我有一个由 WDBackup(西部数据外置硬盘备份实用程序)创建的备份目录,其中包含每天备份的目录以及备份内容的增量内容。
因此层次结构如下所示:
20100101
My Documents
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My song.mp3 # modified 20100101
20100102
My Documents
Important Docs
Taxes.doc
My Music
My Song.mp3 # modified 20100102
...etc...
仅备份已更改的内容,并且所做的第一个备份包含选择用于备份的所有文件。
我现在想做的是增量复制,同时保持文件夹结构,从最旧到最新,将每个带日期的文件夹复制到“合并”文件夹中,以便它覆盖旧内容并保留新内容。
例如,如果仅使用这两个示例文件夹,最终合并的文件夹将如下所示:
Merged
My Documents
Important Docs
Taxes.doc
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My Song.mp3 # modified 20100102
希望这是有道理的。
谢谢,
乔什
I have a backup directory created by WDBackup (western digital external HD backup util) that contains a directory for each day that it backed up and the incremental contents of just what was backed up.
So the hierarchy looks like this:
20100101
My Documents
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My song.mp3 # modified 20100101
20100102
My Documents
Important Docs
Taxes.doc
My Music
My Song.mp3 # modified 20100102
...etc...
Only what has changed is backed up and the first backup that was ever made contains all the files selected for backup.
What I'm trying to do now is incrementally copy, while keeping the folder structure, from oldest to newest, each of these dated folders into a 'merged' folder so that it overrides the older content and keeps the new stuff.
As an example, if just using these two example folders, the final merged folder would look like this:
Merged
My Documents
Important Docs
Taxes.doc
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My Song.mp3 # modified 20100102
Hope that makes sense.
Thanks,
Josh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 bash for 循环中使用 rsync,例如:
请注意,在真正运行之前,您可能只想小心谨慎并测试它实际上会执行您想要的操作 - 为此,您可以使用 rsync 的
- n
标志进行“试运行”:You can use rsync in a bash for loop, e.g.:
Note that before running this for real you might just want to be cautious and test that it's actually going to do what you want it to - for this you can use rsync's
-n
flag to do a "dry run":如果目录名称实际上采用 YYYYMMDD 形式,您可以对它们进行排序。
因此,只需从较旧的开始一次遍历它们并将所有内容复制到目的地,覆盖以前的内容即可。效率很低,但有效。
尽管它很丑陋,但在几乎所有具有 bash 的 UNIX 系统上也应该具有相当的可移植性。
有关详细信息,请参阅 bash(1)、ls(1) 和 sort(1)。
If directory names are actually in the YYYYMMDD form you can just sort 'em.
So it's just a matter of traversing them one at a time starting from the older and copying everything to the destination, overwriting previous stuff. Pretty inefficient, but works.
Ugly as it is, should also be fairly portable on nearly every unix system that has bash.
See bash(1), ls(1) and sort(1) for details.