[PC-BSD Commits] r18239 - in pcbsd/current/src-sh/warden: bin scripts/backend

svn at pcbsd.org svn at pcbsd.org
Mon Aug 6 10:16:51 PDT 2012


Author: kris
Date: 2012-08-06 17:16:51 +0000 (Mon, 06 Aug 2012)
New Revision: 18239

Added:
   pcbsd/current/src-sh/warden/scripts/backend/cronsnap.sh
   pcbsd/current/src-sh/warden/scripts/backend/zfscronsnap.sh
Modified:
   pcbsd/current/src-sh/warden/bin/warden
   pcbsd/current/src-sh/warden/scripts/backend/functions.sh
Log:

Add new functionality to warden CLI. Now you can schedule daily / hourly
cron snapshot creation of jails. You may also set the number of days worth
of snapshots you want to create, and older ones will be pruned automatically



Modified: pcbsd/current/src-sh/warden/bin/warden
===================================================================
--- pcbsd/current/src-sh/warden/bin/warden	2012-08-06 17:10:17 UTC (rev 18238)
+++ pcbsd/current/src-sh/warden/bin/warden	2012-08-06 17:16:51 UTC (rev 18239)
@@ -60,6 +60,7 @@
  zfslistclone - List clones of jail snapshots
   zfslistsnap - List snapshots of a jail
  zfsclonesnap - Clone a jail snapshot
+  zfscronsnap - Schedule snapshot creation via cron
 zfsrevertsnap - Revert jail to a snapshot
    zfsrmclone - Remove a clone directory
     zfsrmsnap - Remove snapshot of a jail
@@ -157,6 +158,31 @@
 "
 };
 
+help_zfscronsnap()
+{
+ title
+ echo "Help zfscronsnap
+
+Schedule a ZFS jail snapshot
+
+Usage:
+
+  warden zfscronsnap <IP> <action> <frequency> <daysToKeep>
+  
+  action = start / stop
+  frequency = daily / hourly
+  daysToKeep = Number of days to keep snapshots
+
+Example:
+
+  warden zfscronsnap 192.168.0.5 start daily 10
+
+  or
+
+  warden zfscronsnap 192.168.0.5 stop
+"
+};
+
 help_zfsrevertsnap()
 {
  title
@@ -487,6 +513,7 @@
            zfslistclone) help_zfslistclone ;;
            zfsrevertsnap) help_zfsrevertsnap ;;
            zfsclonesnap) help_zfsclonesnap ;;
+           zfscronsnap) help_zfscronsnap ;;
            zfsrmsnap) help_zfsrmsnap ;;
            zfsrmclone) help_zfsrmclone ;;
            *) help_main ;;
@@ -847,6 +874,24 @@
          ${PROGDIR}/scripts/backend/zfsclonesnap.sh "${IP}" "$SNAP"
          ;;
 
+ zfscronsnap) require_root
+         IP="$2"
+         if [ -z "$IP" ]
+         then
+           echo "ERROR: No IP specified!"
+           exit 1
+         fi
+
+         if [ ! -e "${JDIR}/${IP}" ]
+         then
+           echo "ERROR: No such jail!"
+           exit 1
+         fi
+	 set_warden_metadir
+         ${PROGDIR}/scripts/backend/zfscronsnap.sh "${IP}" "$3" "$4" "$5"
+         ;;
+
+
  zfsrevertsnap) require_root
          IP="$2"
          SNAP="$3"

Modified: pcbsd/current/src-sh/warden/scripts/backend/functions.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2012-08-06 17:10:17 UTC (rev 18238)
+++ pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2012-08-06 17:16:51 UTC (rev 18239)
@@ -384,3 +384,19 @@
    JMETADIR="${JDIR}/.${IP}.meta"
    export JMETADIR
 }
+
+enable_cron()
+{
+   cronscript="${PROGDIR}/scripts/backend/cronsnap.sh"
+   grep -q "${cronscript}" /etc/crontab
+   if [ $? -eq 0 ] ; then return 0 ; fi
+   echo "2     *        *       *       *        root    ${cronscript}" >> /etc/crontab
+   # Restart cron
+   /etc/rc.d/cron restart >/dev/null 2>/dev/null
+}
+
+is_num()
+{
+        expr $1 + 1 2>/dev/null
+        return $?
+}



More information about the Commits mailing list