Sylvain Dusart schrieb:
> Hi Joe,
>
> I use this script to delete my empty snapshots :
>
> #!/bin/bash
>
> NOW=$(date +%Y%m%d-%H%M%S)
>
> POOL=tank
>
> zfs snapshot -r [EMAIL PROTECTED]
>
> FS_WITH_SNAPSHOTS=$(zfs list -t snapshot | grep '@' | cut -d '@' -f 1 | uniq)
>
> for fs in $FS_WITH_SNAPSHOTS ; do
>
> EMPTY_SNAPSHOTS=$(zfs list -t snapshot | grep -v "@$NOW" |
> grep "${fs}@" | awk ' $2 == "0" { print $1 }' )
>
> for snapshot in $EMPTY_SNAPSHOTS ; do
> echo "Destroying empty snapshot $snapshot"
> zfs destroy $snapshot
> done
> done
>
> Hope that helps,
This script is broken - because the "zfs list" output is broken. You
might end up deleting snapshots with data in it.
Data which is in more than one snapshot will not get counted in the "zfs
list" output at all.
Let's try it with an example:
# zfs create export/test
# mkfile 10m /export/test/bla
# zfs snapshot export/[EMAIL PROTECTED]
# zfs snapshot export/[EMAIL PROTECTED]
# rm /export/test/bla
Now both snapshots should contain (the same) 10MB of valuable data (the
file /export/test/bla just removed). But:
# zfs list -r export/test
NAME USED AVAIL REFER MOUNTPOINT
export/test 24.5K 171G 24.5K /export/test
export/[EMAIL PROTECTED] 0 - 24.5K -
export/[EMAIL PROTECTED] 0 - 24.5K -
... indicates two empty snapshots. But after removing one of the
snapshots ...
# zfs destroy export/[EMAIL PROTECTED]
... the data magically shows up on the second snapshot (in my case not
10MB, because the compression setting was inherited from the parent zfs)
# zfs list -r export/test
NAME USED AVAIL REFER MOUNTPOINT
export/test 47K 171G 24.5K /export/test
export/[EMAIL PROTECTED] 22.5K - 24.5K -
Your script above would have deleted both snapshots. One possible
solution would be to re-evaluate the "zfs list" output after each
snapshot deleted. This way the last one of data-identical snapshots
would be preserved. Something like:
while :; do
EMPTYSNAPSHOT=$(zfs list -Ht snapshot -o name,used | \
awk '$2 == 0 { print $1; exit }')
[ -n "$EMPTYSNAPSHOT" ] || break
zfs destroy $EMPTYSNAPSHOT
done
Daniel
_______________________________________________
zfs-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss