如何有效地仅将修改过的文件从磁盘复制到外部 USB?

mer*_*114 11 command-line backup

my_projects_linux在 Ubuntu 文件系统内部有一个名为的目录,其中包含我多年来的所有工作。该目录包含文件、子目录等。

出于备份目的,我偶尔会将此目录及其所有内容复制到外部硬盘驱动器。

因此,我的外部驱动器的内容如下所示:

/mounted_drive/my_projects_linux
/mounted_drive/my_projects_windows  # the same idea to backup Windows work
Run Code Online (Sandbox Code Playgroud)

因此,我正在寻找的是一个命令:

  1. 将作为

    cp /home/my_projects_linux /mounted_drive/my_projects_linux
    
    Run Code Online (Sandbox Code Playgroud)

    它应该用我电脑上的新内容替换外部磁盘中的旧文件、子目录、子目录内的文件等。

  2. 要快。它应该只复制修改过的文件或新创建的文件。考虑到my_projects_linux> 50GB的大小,全部复制需要一个多小时,太慢了。实际上,自上次备份以来,通常只有几 MB 发生了变化,因此理论上可以更快地制作副本。

怎么做?

我在谷歌上搜索了带有-u标志的cp可能符合我的需求。这会起作用(例如,它会正确处理子目录的子目录吗)?

此外,将文件系统存储在外部磁盘上是否是一种适当的备份方式,还是有一种更好的方式?例如,使用云?请注意,更好的方法应该是简单的,否则它不会超过执行一个 shell 命令的容易程度。

Oli*_*Oli 14

你在某种程度上描述了rsync设计的目的。来自man rsync

   Rsync  finds  files  that  need to be transferred using a "quick
   check" algorithm (by default) that looks  for  files  that  have
   changed  in  size  or in last-modified time.  Any changes in the
   other preserved attributes (as requested by options) are made on
   the  destination  file  directly  when the quick check indicates
   that the file’s data does not need to be updated.
Run Code Online (Sandbox Code Playgroud)

关于网络也有很多胡言乱语,但在本地也很高兴。
基本上所有你需要的是:

rsync -rtv /home/my_projects_linux /mounted_drive/my_projects_linux
Run Code Online (Sandbox Code Playgroud)

有一吨的可用选项,但-rtv将同步[R ecursively,保持牛逼imecodes相同,而被v关于它在做什么erbose。

  • `-a` 是归档模式;它等于`-rlptgoD`,其中包括答案中的`-rt`。OP 的问题不需要控制台输出,因此如果您不想看到滚动的内容,则无需添加“-v”。 (4认同)