Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Extending on this question:

Automatically sync a folder to a USB when USB is plugged in?

I do not want an automatic script but just a small bash script to do the following:

  • Copy current ~/Documents/ to a backup folder
  • Copy newer files from USB/Documents to ~/Documents/
  • Copy and carry over deletions from ~/Documents/ to USB/Documents/

I now have:

# Backup local:
rsync -av ~/Documents/ ~/backup20112012/Documents/

# Synch new files from USB:
rsync -auv /media/20CC-A5E5/Documents/ ~/Documents/

# Sync and delete USB:
rsync -av --delete ~/Documents/ /media/20CC-A5E5/Documents/

which works with one exception. If I delete a file in ~/Documents, it is created again in step 2 (cause it is on USB). Is there a way to omit copying files that have been deleted in step two?

share|improve this question
There is something wrong with your requirements, there is no way to distinguish a deleted from a non existing file. So, "carry over deletions from ~/Documents" implies that you want to keep only files which are already present in ~/Documents, such conflicts with the "Copy newer files from USB" which is likely to include files which are not present on ~/Documents. – João Pinto Sep 15 '11 at 17:58
What about saving the time of the last run in a file and only copy files made after that from the USB? – Zagga Sep 15 '11 at 18:04
That would not work when you rename files on the USB, actually your requirements do no address "mv" – João Pinto Sep 15 '11 at 18:59

1 Answer

Your requirements are a little strange. It looks like you want to synchronize ~/Documents and USB/Documents so that they have the same content. If that's so, use unison Install unison, which is the tool of choice when you're looking for a bidirectional rsync.

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.