1

I want to recursively copy one directory over another, however I only want to copy differences. The reason is that I'm doing this on Solaris on a volume which is snapshot, i.e. if I'm copying 100gig across to a directory that already contains 100gig but only 5gig is different I don't want the whole 100gig to be copied across as that will fill the disk with 200gig of data (100gig of new data and 100g of old data held by the snapshot).

I want the final result to only take 105gig of space (i.e. 5 gig of new data and 100 gig of old data).

Removing the snapshot isn't an option as we need a quick rollback option.

It would great to only copy differences on a block basis, but even copying entire files only if they're different would be ok.

The -u of cp won't work as the files at the destination may have newer timestamps.

Also, I should note that the source and destination directories are on different volumes.

How can I do this?

3
  • 1
    I believe you can do this with rsync but I can't give you the invocation off the top of my head. Search for rsync questions here, I expect this has already been discussed.
    – dubiousjim
    Commented Dec 18, 2012 at 2:02
  • DO you have GNU utilities (cp & rsync) available?
    – Stobor
    Commented Dec 18, 2012 at 3:17
  • when I originally read the question, I thought the questioner wanted to manually segregate the newly copied data from the existing data. Now it sounds like he's content to copy the new data into the existing destination, and let the filesystem/snapshotting driver (e.g. zfs) sort them out. In that case, rsync is even more obviously the right tool; I suggest some flags to look at in a comment to one of the answers below.
    – dubiousjim
    Commented Dec 18, 2012 at 17:35

2 Answers 2

6

Rsync is your tool:

rsync --archive source/ dest/

Archive is just a compound option consisting of:

--recursive      # recurse into directories
--links          # copy symlinks as symlinks
--perms          # preserve permissions
--times          # preserve times
--group          # preserve group
--owner          # preserve owner
--devices        # preserve device files
--specials       # preserve special files

If you don't have rsync on your system you should get it. You could probably create some other solution using other tools, but if you are looking for that one program that does this one thing well (unless I misunderstand your question), what you are looking for is rsync.

1
  • 2
    Yes, rysnc is probably the right tool but the --archive flag doesn't (on its own) suffice to meet the questioner's needs. Look into the --size-only and --checksum and --update and --ignore-existing and --inplace options. Also --delete or a similar flag, which are often used together with --archive.
    – dubiousjim
    Commented Dec 18, 2012 at 17:33
0

If you want a block level copy, you can create a new snapshot and send an incremental stream. This assumes you are using ZFS and not UFS snapshots and that your directory (closely enough) match the file system it is in.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .