Skip to content

--backup does not keep empty directories in --backup-dir #842

Description

@mgutt

rsync deletes empty directories instead of moving them to the --backup-dir if --backup is used.

Version

root@atum:/mnt/disk1/test# rsync -V
rsync  version 3.4.1  protocol version 32

Test

# mkdir /tmp/src
# mkdir /tmp/dst
# mkdir /tmp/dst/sub
# mkdir /tmp/dst/sub/empty_dir
# touch /tmp/dst/sub/file.txt
# mkdir /tmp/backup_dir
# find /tmp/dst
/tmp/dst
/tmp/dst/sub
/tmp/dst/sub/file.txt
/tmp/dst/sub/empty_dir
# rsync -r --itemize-changes --delete --backup --backup-dir="/tmp/backup_dir/" /tmp/src/ /tmp/dst
*deleting   sub/empty_dir/
*deleting   sub/file.txt
*deleting   sub/

Result:

# find /tmp/backup_dir/
/tmp/backup_dir/
/tmp/backup_dir/sub
/tmp/backup_dir/sub/file.txt

Expected result:

# find /tmp/backup_dir/
/tmp/backup_dir/
/tmp/backup_dir/sub
/tmp/backup_dir/sub/empty_dir
/tmp/backup_dir/sub/file.txt

Research

It seems this bug is already known since 2014:
https://bugzilla.samba.org/show_bug.cgi?id=10724#c3

I wonder if that commit was trying to fix another bug that exists in at least 3.1.0, and possibly other versions. When an empty directory is deleted from source but exists in target, and the --delete option is enabled, the empty directory is not placed in --backup-dir. Going to see if I can figure out what exactly the commit changed.

But it seems nobody fixed this or opened an issue for that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions