Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #
- # Create symbolic links from sanoid's autosnaps
- # to something that samba's vfs_shadow_copy2 can read
- #
- # This script should be run from a directory at the root
- # of a ZFS filesystem
- #
- # Known caveats:
- # will break if sanoid creates snapshots with spaces
- # or funny characters in the snapshot names
- #
- set -e
- target_snaproot=$(cd $(dirname "$0"); pwd)
- zfs_snaproot=$(cd "$target_snaproot/../.zfs/snapshot"; pwd)
- # bail if we can't find ZFS's snapshot directory
- [ -d "$zfs_snaproot" ] || ( echo "ZFS snap dir $zfs_snaproot not found" ; exit )
- while read snapdate;
- do
- source_snapdir=""
- target_snapdir="$target_snaproot/$snapdate"
- # determine which snapshot to symlink for a given date
- # i.e. if an there is a yearly and monthly snapshot for the same date, use the yearly one
- if [ -d "$zfs_snaproot/autosnap_${snapdate}_yearly" ] ; then
- source_snapdir="$zfs_snaproot/autosnap_${snapdate}_yearly" ;
- elif [ -d "$zfs_snaproot/autosnap_${snapdate}_monthly" ] ; then
- source_snapdir="$zfs_snaproot/autosnap_${snapdate}_monthly" ;
- elif [ -d "$zfs_snaproot/autosnap_${snapdate}_daily" ] ; then
- source_snapdir="$zfs_snaproot/autosnap_${snapdate}_daily" ;
- elif [ -d "$zfs_snaproot/autosnap_${snapdate}_hourly" ] ; then
- source_snapdir="$zfs_snaproot/autosnap_${snapdate}_hourly" ;
- fi;
- # this shouldn't happen - but check the next date if we
- # don't find one of sanoid's snapdirs
- [ -z "$source_snapdir" ] && continue;
- echo ln -sf "$source_snapdir" "$target_snapdir"
- ln -sf "$source_snapdir" "$target_snapdir"
- done < <( cd "$zfs_snaproot"; ls -1 -d autosnap* | perl -ne '/autosnap_(.+)_(monthly|hourly|yearly|daily)/; print "$1\n";' | sort -u )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement