You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will not work on SunOS platforms, so I've changed some bits:
the timestamps used in snapshots list are UNIX timestamps now (-p parameter) for easy comparison
the absolute oldest date computation is added for SunOS platform
the "from " is not outputted anymore, because it is not in the snapshots list
--- delete_snapshots.sh Sat Dec 5 10:03:02 2015
+++ /opt/custom/sbin/delete_snapshots Sat Dec 5 10:02:00 2015
@@ -79,6 +79,8 @@
platform='bsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='bsd'
+elif [[ "$unamestr" == 'SunOS' ]]; then
+ platform='sunos'
else
echo -e "unknown platform $unamestr 1>&2"
exit 1
@@ -93,6 +95,8 @@
if [[ "$platform" == 'linux' ]]; then
compare_timestamp=`date --date="-$(echo $compare_seconds) seconds" +"%s"`
+elif [[ "$platform" == 'sunos' ]]; then
+compare_timestamp=$((`date +"%s"` - $compare_seconds))
else
compare_timestamp=`date -j -v-$(echo $compare_seconds)S +"%s"`
fi
@@ -99,7 +103,7 @@
# get a list of snapshots sorted by creation date, so that we get the oldest first
# This will allow us to skip the loop early
-snapshots=`zfs list -H -t snapshot -o name,creation -s creation | grep $pattern`
+snapshots=`zfs list -H -t snapshot -o name,creation -s creation -p | grep $pattern`
if [[ -z $snapshots ]]; then
echo "no snapshots found for pattern $pattern"
@@ -112,14 +116,8 @@
IFS=$'\n'
for line in $snapshots; do
snapshot=`echo $line | cut -f 1`
- creation_date=`echo $line | cut -f 2`
+ creation_date_timestamp=`echo $line | cut -f 2`
- if [[ "$platform" == 'linux' ]]; then
- creation_date_timestamp=`date --date="$creation_date" "+%s"`
- else
- creation_date_timestamp=`date -j -f "%a %b %d %H:%M %Y" "$creation_date" "+%s"`
- fi
-
# Check if the creation date of a snapshot is less than our compare date
# Meaning if it is older than our compare date
# It is younger, we can stop processing since we the list is sorted by
@@ -130,10 +128,10 @@
echo "DELETE: $snapshot from $creation_date"
zfs destroy $snapshot
else
- echo "WOULD DELETE: $snapshot from $creation_date"
+ echo "WOULD DELETE: $snapshot"
fi
else
- echo "KEEP: $snapshot from $creation_date"
+ echo "KEEP: $snapshot"
echo "No more snapshots to be processed for $pattern. Skipping.."
break
fi
The text was updated successfully, but these errors were encountered:
I've moved away from Illumos for 5 years now :)
I highly recommend a "keep the last N snaphots" pattern instead of deleting by date.
Nowadays I use the following script to cleanup by the above mentioned pattern.
#!/bin/bash
ROOT_DS=slow
KEEP=3
for i in $(zfs list -H -r $ROOT_DS -o name); do
for s in $(zfs list -S creation -H -t snapshot -o name $i | tail -n +${KEEP}); do
echo "Deleting $s"
zfs destroy $s
done
done
tail in SunOS may be different, so you need to test. That syntax is used to display the last lines except .
few($KEEP)
This will not work on SunOS platforms, so I've changed some bits:
The text was updated successfully, but these errors were encountered: