复制文件结构保留链接

复制文件结构保留链接

我有一个目录,里面全是增量备份(约 20GB),我需要将其从一个分区复制(或移动)到另一个分区。此目录包含每日快照,这些快照是使用 cp -al 创建符号链接以复制文件(而不是副本)而生成的。

我需要按原样复制此结构并保留其中的链接,但是当我运行 cp -r 时,似乎创建了文件而不是链接(我假设这是因为在复制了一小部分后,副本比原始副本使用了更多的可用磁盘空间)。

如何将此目录复制到另一个磁盘,同时保留链接结构?我怎么知道它是作为链接复制的?(似乎很难验证,因为 du 无论如何都包含文件大小)

答案1

使用rsync。来自其手册页:

          rsync -avz foo:src/bar /data/tmp

   This  would  recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, which ensures that sym‐
   bolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer.  Additionally, compression will be used to reduce the size of data portions of the transfer.

值得一提的是,du可以跟随符号链接或不跟随符号链接:

   -L, --dereference
          dereference all symbolic links

   -P, --no-dereference
          don't follow any symbolic links (this is the default)

答案2

tar 可能会有帮助,例如

tar cf - . | (cd /otherdirectory; tar xvf -)

相关内容