I want to rsync my root directory to an external hard disk mounted under /media/guettli/backup1t/.

rsync -xavi --delete --delete-excluded \
  --exclude '...' \
  /  /media/guettli/backup1t/

Something went wrong with the mounting and rsync happily created /media/guettli/backup1t/ in the root directory and rsynced copied files there and not onto the external hard drive.

I would like to avoid this.

I could do it with a shell script which checks that /media/guettli/backup1t/ exists before starting rsync, but I would prefer an option to rsync.

How can I tell rsync to not start the sync, if the destination does not exist?


You can try do something like that:

rsync -xavi --rsync-path="[[ -d /media/guettli/backup1t ]] && rsync" --delete --delete-excluded \
  --exclude '...' \
  /  /media/guettli/backup1t/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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