[OpenIndiana-discuss] How to let find 'see' .zfs directories
Udo Grabowski (IMK)
udo.grabowski at kit.edu
Thu Mar 20 07:16:11 UTC 2014
On 20/03/2014 04:02, Harry Putnam wrote:
> Probably some obvious thing going on here but I'm not see how find all
> '.zfs' directories under a zfs system hierarchy.
>
> Just running something like
>
> cd /rmh/ (that is 'p2/rmh' in zpool talk)
>
> find . -type d -name 'snapshot'
>
> No hits whatsoever, when I know there are 4-5 under there.
>
> I wanted to setup some homeboy snapshot destroys on the basis of mving
> to all .zfs/snapshot directories and using ls -t, sed, zfs snapshot destroy to
> get rid of snaps beyond the most recent 8 in the directory
>
> So is something like 'zfs -H -t snapshot -o name' the only way to
> ferret out actual addresses of the snaps?
>
> I'd sooner use basic oldschool unix tools if possible
>
Our rolling snapshot script to be used in a cron,
adapt to your needs:
# ## usage 'roll_snapshot filesystem 8'
# cat roll_snapshot
#!/sbin/sh
root=`/sbin/mount | grep '^/ '|nawk '{print $3;}'`
fsys="$root"
if [ -n "$1" ] ; then
fsys=$1
fi
roll=3
if [ -n "$2" ] ; then
if (echo $2|grep '^[0-9]*$'>/dev/null); then
roll=$2
else
echo "$2 is not a number."
exit 1
fi
fi
if (zfs list $fsys >/dev/null) ; then
oldest=`zfs list -t snapshot| cut -d' ' -f1 | grep
$fsys'@[0-9]\{4,4\}-[0-1][0-9]-[0-3][0-9]_[0-2][0-9]:[0-5][0-9]:[0-6][0-9]'|sort
-r|tail +$roll`
if [ -n "$oldest" ] ; then
for z in $oldest; do zfs destroy $z ;done
fi
zfs snapshot $fsys@`date '+%F_%T`
else
echo "$fsys is not a ZFS filesystem, cannot snapshot."
exit 1
fi
More information about the OpenIndiana-discuss
mailing list