Giter Club home page Giter Club logo

zfs-scripts's Introduction

zfs-scripts

zfs-scripts's People

Contributors

phuesler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

zfs-scripts's Issues

Enhancement to delete_snapshots

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.