The intersection of technology and leadership

Synchronising two external hard drives with rsync on a mac

This is more of a reminder for myself so I don’t need to keep googling or looking at man when I need to look up the syntax.

Let’s assume you have two hard drives, ones called PHOTOS the other other BACKUP. You can use the following command to synchronise photos (including removing all files that were deleted on PHOTOS to BACKUP.) also ignoring backup files (.* files).

rsync -av --delete --exclude=".*" /Volumes/PHOTOS/ /Volumes/BACKUP

It’s nice to test this on a smaller folder first if you like. You should note the slash and lack of slash matters. To do a dry run try:

rsync -avn --delete --exclude=".*" /Volumes/PHOTOS/ /Volumes/BACKUP

or alternatively:

rsync -av --dry-run --delete --exclude=".*" /Volumes/PHOTOS/ /Volumes/BACKUP

Happy backups!

11 Comments

  1. Bill

    Thanks Pat! I was looking to do exactly this for my external drive with my media library. What is the purpose of excluding * files?

  2. Patrick

    Great. It’s not to exclude all files (*), but to ignore dot-star (.*) files which are often the backup or hidden files (e.g. IMG.JPG.bak) or on mac, there is always this .DS_Store file that gets created that I want to ignore by default

  3. Greg Lawrence

    Thanks Pat, I’m looking to do this but am not a programmer – and wanted to check – do I type these commands in Terminal?
    Thanks! Greg

  4. Patrick

    Hi Greg! Yes, you’re right. These should be typed in the command line which can be done via Terminal

  5. Chris

    Thanks a lot for this! For the people who want to put it in a little automator script app see:

  6. Michael

    Works fine, with one exception. It removes deleted files, but deleted folders remain. Any solution for that?

  7. lhambly

    Thanks for the great info! SHouldn’t it be rsync -av –delete –exclude=”.*” /Volumes/PHOTOS/ /Volumes/PHOTO_BACKUP? Also what command would you use to stop the sync? Thanks again!

  8. Patrick

    Sorry I’d updated the command (as I’d renamed the external HDD to be shorter). I’ve updated the post, thanks. To stop the sync, I use the terminal interrupt (on a Mac it’s CTRL-C)

  9. hansi

    Anyone knows how to preserve finder tags? Some say that -E used to work, but its not.
    Thanks a lot!

  10. Mick

    Thank you for that, I have maybe a silly question, as I’m not an expert: if these are external drives does rsync “pass by” the Mac to copy the files from A to B? I mean mike if you di d a copy with the finder or does the Mac act as if it was a remote control so to say? I ask because I used rsync to copy files from the Mac to an external drive, but I was thinking that if iw ant to copy from drive a to b it would first pass by the Mac..

  11. Patrick

    Hi Mick,

    Thanks for your question. I’m also not an expert at rsync and do not know how the internals work, so I can only guess that I think it is simply copying data (i.e. blocks) from external disk to external disk and does not write to the Mac disk. I can’t be confident as I don’t know how it’s implemented, but I would say that in your example, it makes it more like a Mac is acting like a remote control.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 patkua@work

Theme by Anders NorenUp ↑