Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got what is apparently a slightly uncommon backup requirement:

I have physical access to both disks, and transfer will only ever go one way. I want to completely replicate the first disk to the second, and then update it once a month manually afterward.

I saw this thread: http://stackoverflow.com/questions/15208/whats-the-best-linux-backup-solution, here's where my needs differ.

Both disks are USB, and there is the possibility that their mount locations will change from time to time. I need to be able to specify a source directory (/media/A) and a destination (/media/B) and have A copy to B without simply starting from scratch each time, with the end result being B and A are identical. I don't require time machine-style incremental changes, don't want to tar or encrypt anything, don't need to send this over a network.

Thoughts? I'm running Ubuntu 10.04.

share|improve this question

migrated from stackoverflow.com Jul 19 '10 at 13:18

This question came from our site for professional and enthusiast programmers.

7 Answers 7

up vote 8 down vote accepted

Rsync is a very nice utility for this... Specifically:

   rsync -Pav --delete --force-delete /media/A/ /media/B/

(note ending slashes)

   man rsync 

will give you more info

share|improve this answer
    
--force-delete is deprecated, and I've added --exclude 'lost+found', otherwise it's great –  hewhocutsdown Jul 19 '10 at 4:02
    
I'm using "rsync -Pav --delete --exclude 'lost+found' /source /destination" and "tree >> ~/YYYY-MM-DD_filelist" to keep records. Thanks! –  hewhocutsdown Sep 22 '10 at 19:14

I recommend the rsync utility for this purpose.

share|improve this answer

rsync should be adaptable to your needs. Simply give it the source and destination directories, and it does the rest.

share|improve this answer
cp -au /media/A/* /media/B

seems like it should be sufficient. Anybody with brighter ideas? Objections?

share|improve this answer

rsync would work best as the others have shown above, as it will update automatically. You could also use dd to copy the raw disk data from one disk to another ("cloning" the disk) which would be easier to implement.

share|improve this answer

I recommend unison. Homepage link

I use it for day-to-day syncs between my home computer and laptop, one-way sync will be even easier.

The config will be very simple:

root = /media/A
root = /media/B

If /media/b is empty, the first time it will be propagated with the contents of /media/A.

Later, if something changes in /media/A, unison will change /media/B to be identical to /media/A. It will also work the other way.

share|improve this answer

If they're both local and fast and you want the most accurate changes, then I would use dd to just copy everything. If you're running this interactively, you can use pv to get a nice progress bar. When you do this you must make sure the destination disk is not mounted.

To cope with the fact that the disks may mount at different points, I would access them by their ID, rather than their transient device name.

So in short:

umount /dev/disks/by-id/blah-blah pv < /dev/disks/by-id/ata-Patriot_Torqx_128GB_SSD_blah > /dev/disks/by-id/blah-blah

The good thing is that this will copy the bootloader, all partitions, etc. One drawback is that if the filesystem becomes corrupt, that corruption will propagate. But presumably you have other backups to cope with needing to go back in time.

To answer some of the others, because I can't comment yet:

The problem with Carl's "cp" is that it won't delete deleted files.

The problem with rsync -Pav is that it won't propagate hardlinks, but you could add -H to do that.

I love Unison, but it's not a good choice here because it writes everything into temporary directories before moving them into place, so it may not work on disks that are nearly full. It does a full upfront scan so it will tend to be slower. And it keeps some accounting information that you don't need for one-way syncs.

share|improve this answer

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.