Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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 Dec 18 '12 at 2:02
    
DO you have GNU utilities (cp & rsync) available? –  Stobor Dec 18 '12 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 Dec 18 '12 at 17:35
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
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 Dec 18 '12 at 17:33
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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