rsync --delete and --exclude

14,091

There are a number of delete options with rsync. They are and perform as follows:

            --delete                delete extraneous files from dest dirs
            --delete-before         receiver deletes before xfer, not during
            --delete-during         receiver deletes during the transfer
            --delete-delay          find deletions during, delete after
            --delete-after          receiver deletes after transfer, not during
            --delete-excluded       also delete excluded files from dest dirs

Based on this my best guess is that you are looking for the --delete-excluded switch

Note: If the target drive is already full it will likely be required to free up some space before starting rsync again otherwise it might still fail with insufficient disk space.

You can avoid this problem entirely by choosing a target of sufficient size to contain everything you wish to copy.

Source: man rsync

Share:
14,091

Related videos on Youtube

ElHeineken
Author by

ElHeineken

Updated on September 18, 2022

Comments

  • ElHeineken
    ElHeineken over 1 year

    Just a quick question as I'm preparing a backup of my server before moving it form Tokyo to Germany.

    The rsync command uses --delete to sync between source and target as well as --exclude to avoid copying unnecessary files and folders.

    It worked fine four years ago but the amount of data has since increased significantly (as usually). The first try failed after a few hours of copying due to insufficient target disk space.

    Now I would like to add more --exclude options to limit the data usage. If possible I want to avoid deleting everything and starting from scratch (that takes several hours) my question is as follows:

    How does rsync --delete handle directories that were recently marked as --exclude?

    Will they be deleted on the target or will they stay untouched?

  • Elder Geek
    Elder Geek over 7 years
    I think so too.
  • ElHeineken
    ElHeineken over 7 years
    The test was successful, works as advertised. The only thing that should be mentioned though is that there is no particular oder between deleting files and copying new ones. So it might be required to free up some space before starting rsync again otherwise it might still fail with insufficient disk space (as there is no space on the drive and --delete might not be the first thing rsync does). Anyway, thanks again!
  • Elder Geek
    Elder Geek over 7 years
    @ElHeineken Thanks for the feedback. Edited answer for clarity.