rsync - Delete files at source if they do not exist at the destination

StackOverflow https://stackoverflow.com/questions/23459682

  •  15-07-2023
  •  | 
  •  

سؤال

Currently I am using rsync -avz daniel@remotepc:/var/www /home/localuser/rsync --exclude='/var/www/somefolder'", but if a file is deleted on remotepc, I want it to be deleted on the local copy. I wasn't sure if --delete was to be used here, and just wanted to check before I do something stupid and end up losing data.

هل كانت مفيدة؟

المحلول

Why do you care about loosing data if you may only loose local copy? Also, rsync have -n option, which is dry run - it will print everything it would do, but will not perform any changes.

Also, if you're too afraid losing local copy (maybe data is too large to re-download), you could use -b option, which will rename files to filename~ instead of deleting it.

Anyway --delete is what you need, and even maybe --delete-excluded.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top