Incremental backup and empty dirs

Matt McCutchen hashproduct+rsync at gmail.com
Tue May 1 21:08:44 GMT 2007


On 4/30/07, Mark <rsync at renton.name> wrote:
> Hi,
>
> I use rsync with such options:
>
> OPTIONS="-a -u -z -v -S --delete-during --ignore-errors \
>          -b --backup-dir=${PATH_BACKUP}/${DATE_YESTERDAY} \
>          --exclude-from=$IGNORE"
>
> rsync $OPTIONS ${PATH_SRC} \
>       ${PATH_BACKUP}/current
>
> Everything works as it should be, deleted files are transfered everyday
> to a new catalog, determinated by a variable ${DATE_YESTERDAY}.
>
>
> But if an empty dir is deleted from ${PATH_SRC}, then it is
> accordingly deleted from ${PATH_BACKUP}/current, and don`t appear in
> ${PATH_BACKUP}/${DATE_YESTERDAY}.
>
> Do you know what to do it to make empty dirs be transferred
> to ${PATH_BACKUP}/${DATE_YESTERDAY}?

You could use an extra pass at the beginning to back up all dirs about
to be deleted, whether they are empty or not:

rsync -ni ${OPTIONS} ${PATH_SRC} ${PATH_BACKUP}/current \
    | sed -rne 's#^\*deleting (.*)/$#\1#p' \
    | rsync --out-format='backing up %n' --files-from=- \
        ${OPTIONS} ${PATH_BACKUP}/current ${PATH_BACKUP}/${DATE_YESTERDAY}

Matt


More information about the rsync mailing list