cp --update still copies unchanged files

I'm trying to copy only changed files using 'cp -pu' under Linux (Red Hat 6.1, source/destination FS are GlusterFS mounted partitions) but I found that it still tries to copy file seemingly old and unchanged. In fact, just running the same command again would skip to the next file. I can reproduce the problem in the test shown below. Notice that in the test, I hit control-C to stop the interactive cp command the each time it asks. The second run would skip the file asked in the first run. Why does this happen? And is there a better, fast standard tool to copy locally mounted directories? (I could probably try rsync but I don't need to be super accurate since the data are only for testing and I'm concerned about its speed.)

 [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/ ^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/ ^C
1

2 Answers

cp --update doesn't check if the files are different, it just compares timestamps.

Rsync, which you seem to know about already, sounds like a good fit for your situation.

Use rsync -av $d/ /data/staging/./storage01/42/6b/6b42/$d/

2

If you're only concerned with speed, rsync is not an option for a local backup, contrary to what the other answer says. I am confused too by -u, but in the end if it produces what you need on the destination there's probably nothing else as fast. If you need to do frequent updates and always use the same command, hopefully next time the timestamps will be as cp -u expects them.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like