0

I have a special copy (maybe Robocopy) requierement:

I have:

  • A source directory (with sub-directories)
  • A target directory (with sub-directories)

Both directory structures are nearly the same. But in the target directory there are some newer or additional files. I have to copy files from source to target directory that are not newer (or added) in the target directory.

Example:

The file example.doc exists in source and target directory. But the file in the target directory has a newer timestamp (someone worked on this file) and I want not to overwrite this file.

The file example2.doc exists in source and target directory. Both files have the same timestamp. In this case, I want to overwrite the file in the tartet directory with the file from the source directory.

Maybe Robocopy is the Tool for this case... I read all the parameters (and there are many :) but I didn't find a solution.

BTW: This is my first post on stackoverflow :-)

Thank you very much.

Gernot

  • Tip for googling: you're trying to perform one-way sync. – gronostaj Jan 12 '14 at 19:53
0

You can use the rsync command with the backup switch, -b, with the skip newer files on receiver switch, -u, as in the following sequence where the first rsync gets the files over, the second refuses to overwrite a newer file on the receiver, and the third rsync copies the newer file on the sender to the receiver, backing up the file that has been modified on the receiver as xv~ before overwriting it with the sender's xv. The location of the file that is moved aside can be controlled, and put in another location with the --backup-dir=DIR option.

Of course, you can do all this sync'ing on the same filesystem just as easily.

(Hey! That's how Carbon Copy Cloner does most of it's magic! And they charge like $40 for the service... Alas, I digress...)

whmcclos@Williams-MacBook-Pro:~$ rsync -auvb ~/bin whmcclos@localhost:/tmp
building file list ... done
bin/
bin/days
bin/hide
bin/jedit
bin/mlf
bin/most_recent_file -> most_recent_file.pl
bin/most_recent_file.pl
bin/mplayer
bin/mvim
bin/qvim
bin/sys_config
bin/sys_config.log
bin/tree
bin/try
bin/unhide
bin/xv
bin/zed -> zed.pl
bin/zed.pl

sent 18887050 bytes  received 390 bytes  37774880.00 bytes/sec
total size is 18883599  speedup is 1.00
whmcclos@Williams-MacBook-Pro:~$ touch /tmp/bin/xv
whmcclos@Williams-MacBook-Pro:~$ rsync -auvb ~/bin whmcclos@localhost:/tmp
building file list ... done

sent 422 bytes  received 20 bytes  294.67 bytes/sec
total size is 18883599  speedup is 42723.07
whmcclos@Williams-MacBook-Pro:~$ touch /tmp/bin/xv
whmcclos@Williams-MacBook-Pro:~$ touch ~/bin/xv
whmcclos@Williams-MacBook-Pro:~$ rsync -auvb ~/bin whmcclos@localhost:/tmp
building file list ... done
bin/xv

sent 7392 bytes  received 10434 bytes  35652.00 bytes/sec
total size is 18883599  speedup is 1059.33
whmcclos@Williams-MacBook-Pro:~$ ls /tmp/bin/xv*
/tmp/bin/xv  /tmp/bin/xv~
0

The file example2.doc exists in source and target directory. Both files have the same timestamp. In this case, I want to overwrite the file in the tartet directory with the file from the source directory.

The relavent command line switch for this is:

/IS      Include Same files.

Note: Using the /IS switch alone, with no other switches, forces a total refresh of the destination tree.

For more information about the options for Robocopy see this other post I wrote about Robocopy: https://superuser.com/a/566054/144147, which includes external links to more documentation.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.