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

svn at pcbsd.org svn at pcbsd.org
Mon Jul 9 10:25:26 PDT 2012


Author: kris
Date: 2012-07-09 17:25:26 +0000 (Mon, 09 Jul 2012)
New Revision: 17692

Added:
   pcbsd/current/src-sh/warden/scripts/backend/zfsclonesnap.sh
   pcbsd/current/src-sh/warden/scripts/backend/zfslistclone.sh
   pcbsd/current/src-sh/warden/scripts/backend/zfsrmclone.sh
Modified:
   pcbsd/current/src-sh/warden/bin/warden
   pcbsd/current/src-sh/warden/scripts/backend/functions.sh
   pcbsd/current/src-sh/warden/scripts/backend/zfsrevertsnap.sh
Log:

Add new functionality to warden backend

Now we can create, list and remove "clones" of jail snapshots



Modified: pcbsd/current/src-sh/warden/bin/warden
===================================================================
--- pcbsd/current/src-sh/warden/bin/warden	2012-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/bin/warden	2012-07-09 17:25:26 UTC (rev 17692)
@@ -57,8 +57,11 @@
           set - Sets options for a jail
          type - Set the jail type (portjail/normal)
     zfsmksnap - Create a ZFS snapshot of a jail 
+ zfslistclone - List clones of jail snapshots
   zfslistsnap - List snapshots of a jail
+ zfsclonesnap - Clone a jail snapshot
 zfsrevertsnap - Revert jail to a snapshot
+   zfsrmclone - Remove a clone directory
     zfsrmsnap - Remove snapshot of a jail
 "
 };
@@ -103,7 +106,23 @@
 "
 };
 
+help_zfslistclone()
+{
+ title
+ echo "Help zfslistclone
 
+List ZFS clones of a jail
+
+Usage:
+
+  warden zfslistclone <IP>
+
+Example:
+
+  warden zfslistclone 192.168.0.5
+"
+};
+
 help_zfslistsnap()
 {
  title
@@ -121,6 +140,23 @@
 "
 };
 
+help_zfsclonesnap()
+{
+ title
+ echo "Help zfsclonesnap
+
+Clone a ZFS jail snapshot
+
+Usage:
+
+  warden zfsclonesnap <IP> <SNAP>
+
+Example:
+
+  warden zfsclonesnap 192.168.0.5 20120505-140510
+"
+};
+
 help_zfsrevertsnap()
 {
  title
@@ -138,6 +174,23 @@
 "
 };
 
+help_zfsrmclone()
+{
+ title
+ echo "Help zfsrmclone
+
+Remove ZFS clone of a jail
+
+Usage:
+
+  warden zfsrmclone <IP> <CLONE>
+
+Example:
+
+  warden zfsrmclone 192.168.0.5 20120505-140510
+"
+};
+
 help_zfsrmsnap()
 {
  title
@@ -431,8 +484,11 @@
            set) help_set ;;
            zfsmksnap) help_zfsmksnap ;;
            zfslistsnap) help_zfslistsnap ;;
+           zfslistclone) help_zfslistclone ;;
            zfsrevertsnap) help_zfsrevertsnap ;;
+           zfsclonesnap) help_zfsclonesnap ;;
            zfsrmsnap) help_zfsrmsnap ;;
+           zfsrmclone) help_zfsrmclone ;;
            *) help_main ;;
          esac  ;;
 
@@ -747,6 +803,23 @@
          ${PROGDIR}/scripts/backend/zfsmksnap.sh "${IP}"
          ;;
 
+ zfslistclone) 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/zfslistclone.sh "${IP}"
+         ;;
+
  zfslistsnap) require_root
          IP="$2"
          if [ -z "$IP" ]
@@ -764,6 +837,24 @@
          ${PROGDIR}/scripts/backend/zfslistsnap.sh "${IP}"
          ;;
 
+ zfsclonesnap) require_root
+         IP="$2"
+         SNAP="$3"
+         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/zfsclonesnap.sh "${IP}" "$SNAP"
+         ;;
+
  zfsrevertsnap) require_root
          IP="$2"
          SNAP="$3"
@@ -782,6 +873,24 @@
          ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${IP}" "$SNAP"
          ;;
 
+ zfsrmclone) require_root
+         IP="$2"
+         CLONE="$3"
+         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/zfsrmclone.sh "${IP}" "$CLONE"
+         ;;
+
  zfsrmsnap) 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-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2012-07-09 17:25:26 UTC (rev 17692)
@@ -36,6 +36,9 @@
 # Dirs to nullfs mount in X jail
 NULLFS_MOUNTS="/tmp /media /usr/home"
 
+# Clone directory
+CDIR="${JDIR}/clones"
+
 # Function to ask the user to press Return to continue
 rtn()
 {
@@ -288,6 +291,23 @@
   zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}'
 }
 
+listZFSClone() {
+  isDirZFS "${1}" "1"
+  if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
+  tank=`getZFSTank "$1"`
+  echo "Clone Directory: ${CDIR}"
+  echo "-----------------------------------"
+  zfs list | grep -w "^${tank}${CDIR}/${2}" | awk '{print $5}' | sed "s|${CDIR}/${2}-||g"
+}
+
+rmZFSClone() {
+  CLONEDIR="${CDIR}/${3}-${2}"
+  isDirZFS "${CLONEDIR}" "1"
+  if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${CLONEDIR}" ; fi
+  tank=`getZFSTank "$2"`
+  zfs destroy ${tank}${CLONEDIR}
+}
+
 rmZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
@@ -300,6 +320,10 @@
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
   tank=`getZFSTank "$1"`
 
+  # Make sure this is a valid snapshot
+  zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
+  if [ $? -ne 0 ] ; then printerror "Invalid ZFS snapshot!" ; fi
+
   # Check if the jail is running first
   ${PROGDIR}/scripts/backend/checkstatus.sh "${3}"
   if [ "$?" = "0" ]; then
@@ -312,8 +336,8 @@
     fi
   fi
 
-  # Rollback the jail now
-  zfs rollback -R -f $tank${1}@$2
+  # Rollback the snapshot
+  zfs rollback -R -f ${tank}${1}@$2
 
   # If it was started, restart the jail now
   if [ "$restartJail" = "YES" ]; then
@@ -322,6 +346,21 @@
   
 }
 
+cloneZFSSnap() {
+  isDirZFS "${1}" "1"
+  if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
+  tank=`getZFSTank "$1"`
+
+  # Make sure this is a valid snapshot
+  zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
+  if [ $? -ne 0 ] ; then printerror "Invalid ZFS snapshot!" ; fi
+
+  # Clone the snapshot
+  zfs clone -p ${tank}${1}@$2 ${tank}${CDIR}/${3}-${2}
+
+  echo "Snapshot cloned and mounted to: ${CDIR}/${3}-${2}"
+}
+
 # is_symlinked_mountpoint()
 #       Is a mount point, or any of its parent directories, a symlink?
 is_symlinked_mountpoint()

Index: pcbsd/current/src-sh/warden/scripts/backend/zfsclonesnap.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/zfsclonesnap.sh	2012-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/scripts/backend/zfsclonesnap.sh	2012-07-09 17:25:26 UTC (rev 17692)

Property changes on: pcbsd/current/src-sh/warden/scripts/backend/zfsclonesnap.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
Index: pcbsd/current/src-sh/warden/scripts/backend/zfslistclone.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/zfslistclone.sh	2012-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/scripts/backend/zfslistclone.sh	2012-07-09 17:25:26 UTC (rev 17692)

Property changes on: pcbsd/current/src-sh/warden/scripts/backend/zfslistclone.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
Modified: pcbsd/current/src-sh/warden/scripts/backend/zfsrevertsnap.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/zfsrevertsnap.sh	2012-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/scripts/backend/zfsrevertsnap.sh	2012-07-09 17:25:26 UTC (rev 17692)
@@ -13,6 +13,11 @@
 IP="${1}"
 SNAP="${2}"
 
+if [ -z "${SNAP}" ] ; then
+   echo "ERROR: No snapshot specified!"
+   exit 1
+fi
+
 if [ -z "${IP}" ]
 then
   echo "ERROR: No jail specified to start!"

Index: pcbsd/current/src-sh/warden/scripts/backend/zfsrmclone.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/zfsrmclone.sh	2012-07-09 16:34:25 UTC (rev 17691)
+++ pcbsd/current/src-sh/warden/scripts/backend/zfsrmclone.sh	2012-07-09 17:25:26 UTC (rev 17692)

Property changes on: pcbsd/current/src-sh/warden/scripts/backend/zfsrmclone.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*


More information about the Commits mailing list