Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Add the ability for both Life-Preserver and Warden to set an optional
Browse files Browse the repository at this point in the history
comment on snapshots at creation time
  • Loading branch information
Kris Moore committed May 13, 2014
1 parent ee5baaa commit cca8f57
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
14 changes: 13 additions & 1 deletion src-sh/lpreserver/backend/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,23 @@ mkZFSSnap() {
fi
zdate=`date +%Y-%m-%d-%H-%M-%S`
zfs snapshot $flags ${1}@$2${zdate} >${CMDLOG} 2>${CMDLOG}

# Do we have a comment to set?
if [ -n "$3" ] ; then
zfs set lpreserver:comment="$3" ${1}@${2}${zdate}
fi

return $?
}

listZFSSnap() {
zfs list -d 1 -t snapshot | grep -e "^${1}@" | awk '{print $1}'
echo "Snapshot Comment"
echo "-----------------------------------------------"
for i in `zfs list -d 1 -t snapshot | grep -e "^${1}@" | awk '{print $1}'`
do
comment=`zfs get -o value lpreserver:comment $i | grep -v "VALUE"`
echo "$i $comment"
done
}

rmZFSSnap() {
Expand Down
2 changes: 1 addition & 1 deletion src-sh/lpreserver/backend/runsnap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fi

# Create the snapshot now with the "auto-" tag
echo_log "Creating snapshot on ${DATASET}"
mkZFSSnap "${DATASET}" "auto-"
mkZFSSnap "${DATASET}" "auto-" "Automated Snapshot"
if [ $? -ne 0 ] ; then
echo_log "ERROR: Failed creating snapshot on ${DATASET}"
queue_msg "ERROR: Failed creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
Expand Down
4 changes: 3 additions & 1 deletion src-sh/lpreserver/backend/zfsmksnap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ if [ -z "${SNAPNAME}" ]; then
exit_err "No snapshot name specified!"
fi

COMMENT="$3"

# Make the snapshot now
snapStat=0

echo_log "Creating snapshot on ${DATASET}"
mkZFSSnap "${DATASET}" "${SNAPNAME}"
mkZFSSnap "${DATASET}" "${SNAPNAME}" "$COMMENT"
if [ $? -ne 0 ] ; then
echo_log "ERROR: Failed creating snapshot on ${DATASET}"
queue_msg "Snapshot ERROR" "ERROR: Failed creating snapshot on ${DATASET} @ `date`\n\r`cat $CMDLOG`"
Expand Down
7 changes: 4 additions & 3 deletions src-sh/lpreserver/lpreserver
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ Create a new ZFS snapshot of a dataset
Usage:
lpreserver mksnap <dataset> <snapshotname>
lpreserver mksnap <dataset> <snapshotname> <comment>
Example:
lpreserver mksnap tank1/usr/home/kris mysnapshot
or
lpreserver mksnap tank1/usr/home/kris mysnapshot
lpreserver mksnap tank1/usr/home/kris mysnapshot \"Added user bob\"
NOTE:
By default snapshots are recursive and will create snapshots
Expand Down Expand Up @@ -496,7 +496,8 @@ case "$1" in
mksnap) require_root
DATASET="$2"
SNAPNAME="$3"
${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME"
COMMENT="$4"
${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME" "$COMMENT"
;;

listcron) require_root
Expand Down
6 changes: 3 additions & 3 deletions src-sh/warden/bin/warden
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ help_zfsmksnap()
title
echo "Help zfsmksnap
Create a new ZFS snapshot of a jail
Create a new ZFS snapshot of a jail, with an optional comment
Usage:
warden zfsmksnap <Jail>
warden zfsmksnap <Jail> <comment>
Example:
Expand Down Expand Up @@ -1075,7 +1075,7 @@ defaultrouter-ipv6) DEFAULTROUTER="${4}"
if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
set_warden_metadir
${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}"
${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}" "$3"
;;

zfslistclone) require_root
Expand Down
2 changes: 1 addition & 1 deletion src-sh/warden/scripts/backend/cronsnap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ do
fi
fi
if [ "$needSnap" = "1" ] ; then
mkZFSSnap "${JAILDIR}"
mkZFSSnap "${JAILDIR}" "Automated Snapshot"
fi

# Do any pruning
Expand Down
13 changes: 12 additions & 1 deletion src-sh/warden/scripts/backend/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,25 @@ mkZFSSnap() {
rp=`getZFSRelativePath "$1"`
zdate=`date +%Y-%m-%d-%H-%M-%S`
zfs snapshot $tank${rp}@$zdate
# Do we have a comment to set?
if [ -n "$2" ] ; then
zfs set warden:comment="$2" ${tank}${rp}@${zdate}
fi
}

listZFSSnap() {
isDirZFS "${1}" "1"
if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
tank=`getZFSTank "$1"`
rp=`getZFSRelativePath "$1"`
zfs list -t snapshot | grep -w "^${tank}${rp}" | cut -d '@' -f 2 | awk '{print $1}'

echo "Snapshot Comment"
echo "-----------------------------------------------"
for i in `zfs list -t snapshot | grep -w "^${tank}${rp}" | cut -d '@' -f 2 | awk '{print $1}'`
do
comment=`zfs get -o value warden:comment $i | grep -v "VALUE"`
echo "$i $comment"
done
}

listZFSClone() {
Expand Down

0 comments on commit cca8f57

Please sign in to comment.