Well, the name says it pretty much. Once you rename the snapshot on the SnapVault destination from daily.0 to something else, the whole builtin SnapVault snapshot retention isn’t gonna work anymore.
Back when I started all the code-writing, I wasn’t aware of this. One of my co-worker complained to me about it on Wednesday that there are an assfull of snapshots on the SnapVault destination (one snapshot each day since the end of October, meaning more than 50 snapshots per volume, in a total of 12 or so FlexVolumes, making the total about 500 snapshots).
So I took the time to write this little Bash script (yeah, I know I’m mixing a bunch of languages – I really like the KISS principle), which will get the necessary information from the filer (snapvault snap sched needs to be set) and then deletes the over-aged snapshots.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/bin/bash KEY_FILE="/root/.ssh/netapp.dsa" SSH_OPTS="/root/.ssh/netapp-ssh_config" CTRL=$1 ssh_fas() { # $@: commands for Data ONTAP COMMANDS="$@" /usr/bin/ssh -i $KEY_FILE -l root -F $SSH_OPTS $COMMANDS } for volume in $( ssh_fas $CTRL snapvault status | awk '{ print $2 }' | grep vol | cut -d: -f2 | cut -d/ -f3 ); do # Get the snapvault snap sched for this volume SNAP_SCHED="$( ssh_fas $CTRL snapvault snap sched ${volume} )" if [ "$SNAP_SCHED" != "No snapshots scheduled for volume ${volume}." ] ; then SNAP_CLASS="$( echo $SNAP_SCHED | awk '{ print $3 }' )" SNAP_RETENTION="$( echo $SNAP_SCHED | awk '{ print $4 }' | cut -d@ -f1 )" # Now, check the snap list of the volume if there are snapshots named $SNAP_CLASS SNAP_LIST="$( ssh_fas $CTRL snap list ${volume} | egrep -v "(snapvault|$SNAP_CLASS)" | sed '/^$/d' | egrep -v "(Volume|working|date|------------)" | cut -d: -f2 | awk '{ print $2 }' | wc -l )" if [ $SNAP_LIST -ne 0 ]; then TAIL=$((SNAP_LIST-SNAP_RETENTION)) SNAP_NAME="$( ssh_fas $CTRL snap list ${volume} | egrep -v "(snapvault|$SNAP_CLASS)" | sed '/^$/d' | egrep -v "(Volume|working|date|------------)" | cut -d: -f2 | awk '{ print $2 }' | tail -$TAIL )" echo "Processing snapvault destination ${volume}" echo " - total amount of snapshots: $SNAP_LIST" echo " - snapshots to remove: $TAIL" for snap in $SNAP_NAME; do echo "Removing snapshot ${snap}" ssh_fas $CTRL snap delete ${volume} ${snap} | grep -v "deleting snapshot..." done fi fi echo done | mailx -r christian.heim@barfoo.org -s "SnapVault retention for $CTRL" christian.heim@barfoo.org |