我尝试在 Linux 下使用“cp -pu”复制已更改的文件(Red Hat 6.1,源/目标 FS 是 GlusterFS 挂载分区),但我发现它仍然试图复制看似旧的和未更改的文件。事实上,再次运行相同的命令会跳到下一个文件。我可以在下面显示的测试中重现该问题。请注意,在测试中,每次交互 cp 命令询问时,我都会按下 Control-C 来停止它。第二次运行会跳过第一次运行中询问的文件。为什么会发生这种情况?有没有更好、更快的标准工具来复制本地挂载的目录?(我可能会尝试 rsync,但我不需要非常准确,因为数据仅用于测试,我担心它的速度。)
[root@flex 6b42]# for d in *.story; do echo trying $d; ls -al $d
/data/staging/./storage01/42/6b/6b42/$d; cp --parent -rpu -v -i $d
/data/staging/./storage01/42/6b/6b42/; done trying
0a65b244-f342-a120-9a47-62d0c6aa4a26.story
0a65b244-f342-a120-9a47-62d0c6aa4a26.story: total 228 drwxrwx--- 2
somebody somebody 53 Jan 8 02:23 . drwxrwx--- 1280 somebody
somebody 147456 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 2821 Nov 28 2011 data
-rw-r--r-- 1 somebody somebody 0 Nov 28 2011 images
-rw-r----- 1 somebody somebody 17 Nov 28 2011 .timestamp
/data/staging/./storage01/42/6b/6b42/0a65b244-f342-a120-9a47-62d0c6aa4a26.story:
total 228 drwxrwx--- 2 somebody somebody 53 Jan 8 02:23 .
drwxrwx--- 1363 somebody somebody 155648 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 2821 Nov 28 2011 data
-rw-r--r-- 1 somebody somebody 0 Nov 28 2011 images
-rw-r----- 1 somebody somebody 17 Nov 28 2011 .timestamp cp: overwrite
`/data/staging/./storage01/42/6b/6b42/0a65b244-f342-a120-9a47-2d0c6aa4a26.story/.timestamp'?
^C [root@flex 6b42]# for d in *.story; do echo trying $d; ls -al $d
/data/staging/./storage01/42/6b/6b42/$d; cp --parent -rpu -v -i $d
/data/staging/./storage01/42/6b/6b42/; done trying
0a65b244-f342-a120-9a47-62d0c6aa4a26.story
0a65b244-f342-a120-9a47-62d0c6aa4a26.story: total 228 drwxrwx--- 2
somebody somebody 53 Jan 8 02:23 . drwxrwx--- 1286 somebody
somebody 147456 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 2821 Nov 28 2011 data
-rw-r--r-- 1 somebody somebody 0 Nov 28 2011 images
-rw-r----- 1 somebody somebody 17 Nov 28 2011 .timestamp
/data/staging/./storage01/42/6b/6b42/0a65b244-f342-a120-9a47-62d0c6aa4a26.story:
total 228 drwxrwx--- 2 somebody somebody 53 Jan 8 02:23 .
drwxrwx--- 1363 somebody somebody 155648 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 2821 Nov 28 2011 data
-rw-r--r-- 1 somebody somebody 0 Nov 28 2011 images
-rw-r----- 1 somebody somebody 17 Nov 28 2011 .timestamp trying 0aee088d-af48-1236-bcae-6d2033a2acb7.story
0aee088d-af48-1236-bcae-6d2033a2acb7.story: total 232 drwxrwx--- 2
somebody somebody 53 Jan 7 09:39 . drwxrwx--- 1286 somebody
somebody 147456 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 5952 Dec 19 12:40 data
-rw-r--r-- 1 somebody somebody 0 Dec 19 12:40 images
-rw-r----- 1 somebody somebody 17 Dec 19 12:40 .timestamp
/data/staging/./storage01/42/6b/6b42/0aee088d-af48-1236-bcae-6d2033a2acb7.story:
total 232 drwxrwx--- 2 somebody somebody 53 Jan 7 09:39 .
drwxrwx--- 1363 somebody somebody 155648 Apr 30 11:07 ..
-rw-r--r-- 1 somebody somebody 5952 Dec 19 12:40 data
-rw-r--r-- 1 somebody somebody 0 Dec 19 12:40 images
-rw-r----- 1 somebody somebody 17 Dec 19 12:40 .timestamp cp: overwrite
`/data/staging/./storage01/42/6b/6b42/0aee088d-af48-1236-bcae-6d2033a2acb7.story/.timestamp'?
^C
答案1
cp --update
不检查文件是否不同,它只比较时间戳。
您似乎已经了解 Rsync,它听起来很适合您的情况。
使用rsync -av $d/ /data/staging/./storage01/42/6b/6b42/$d/
答案2
如果你只关心速度,rsync 不是一个选项与其他答案相反,本地备份。我我也对 -u 感到困惑,但最终如果它在目标上产生了您需要的内容,那么可能没有其他东西比它更快了。如果您需要频繁更新并始终使用相同的命令,希望下一次时间戳能够如 cp -u 所期望的那样。