Tech Notes And Miscellaneous Thoughts
 

rsync and .zfs snapshot directories

zfsonlinux recently added support for visible .zfs snapshot directories, so you no longer have to mount a snapshot to browse/view/recover files from it.

This is good, but has caused my rsync backup to zfs script to complain about being unable to delete files in the .zfs directory (which is in the backup but not in the source).

e.g.

sending incremental file list
rsync: delete_file: unlink(.zfs/snapshot/2012-03-31/vmlinuz.old) failed: Read-only file system (30)
rsync: delete_file: unlink(.zfs/snapshot/2012-03-31/vmlinuz) failed: Read-only file system (30)
[...]
cannot delete non-empty directory: .zfs/snapshot/2012-03-31
rsync: delete_file: rmdir(.zfs/snapshot/2012-03-31) failed: Device or resource busy (16)
rsync: delete_file: unlink(.zfs/snapshot/2012-03-30/vmlinuz.old) failed: Read-only file system (30)
rsync: delete_file: unlink(.zfs/snapshot/2012-03-30/vmlinuz) failed: Read-only file system (30)
[...]

The solution is to tell rsync to ignore .zfs directories on the destination.

1. use the -F option to make rsync use /.rsync-filter
2. create or add the following line to /.rsync-filter

-r .zfs/***
-s .zfs/***

On the first line, the ‘-‘ makes it an exclude rule, and the ‘r’ indicates that the rule applies to the receiving side. Together, ‘-r’ prevents rsync from attempting to delete the .zfs directories

On the second line, the ‘-s’ indicates that the rule applies to the sending side, preventing rsync from trying to backup any .zfs snapshot directories. This is only useful when backing up a ZFS filesystem.

3 Comments

  1. cas

    another, much simpler, alternative is:

    zfs set snapdir=hidden <zfs-filesystem>

    If you set this on the top-level zfs fs (the pool), then child filesystems will inherit it unless you’ve manually changed that setting on the child form the default (inherit).

    The .zfs directory will still be available for use (e.g. ‘cd .zfs’) but won’t show up in directory listings.

  2. johnny

    weird, i’m running rsync -axvPH –delete –numeric-ids /src /dst.
    src si ext4
    dst is zfs (not .zfs snapshot)
    i still get these errors
    rsync: delete_file: rmdir(usr/src/linux-headers-3.2.0-26-generic/arch) failed: File exists (17)
    cannot delete non-empty directory: usr/src/linux-headers-3.2.0-26-generic

    what could it be? i deleted them with rm in the end… and only in that directory is was complaining…

  3. cas

    could be http://lists.samba.org/archive/rsync/2005-March/011797.html ([Bug 2409] New: rsync doesn’t handle directories changing into symlinks well) which was closed with WONTFIX as being a safety feature.

    you might need –delete-before.

    if it’s not that, try google:  http://www.google.com.au/search?q=rsync%3A+delete_file%3A+rmdir+failed%3A+File+exists

Comments are closed.