forked from extern/zfs-auto-snapshot
mostly untested svcprop performance improvement
This commit is contained in:
parent
15bbf270be
commit
f223b7e139
@ -76,6 +76,25 @@ LOG=""
|
|||||||
# a null string in this variable says we don't.
|
# a null string in this variable says we don't.
|
||||||
HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r')
|
HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r')
|
||||||
|
|
||||||
|
|
||||||
|
# A function to pull in the variables from the FMRI given
|
||||||
|
# as the first argument.
|
||||||
|
function zfs_smf_props {
|
||||||
|
|
||||||
|
SMF_PROPS=$(svcprop -p zfs $1 | \
|
||||||
|
sed -e 's#^zfs/fs-name#zfs/fs_name#g' \
|
||||||
|
-e 's#^zfs/backup-lock#zfs/backup_lock#g' \
|
||||||
|
-e 's#^zfs/snapshot-children#zfs/snapshot_children#g' \
|
||||||
|
-e 's#^zfs/backup-save-cmd#zfs/backup_save_cmd#g' \
|
||||||
|
-e 's#zfs/##g' |\
|
||||||
|
awk '{printf("%s=%s ",$1,$3)}')
|
||||||
|
|
||||||
|
for pair in $SMF_PROPS ; do
|
||||||
|
export "$pair"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# this function validates the properties in the FMRI passed to it, then
|
# this function validates the properties in the FMRI passed to it, then
|
||||||
# calls a function to create cron job that schedules a snapshot schedule based
|
# calls a function to create cron job that schedules a snapshot schedule based
|
||||||
# on the properties set in the service instance.
|
# on the properties set in the service instance.
|
||||||
@ -83,15 +102,16 @@ HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r')
|
|||||||
function schedule_snapshots {
|
function schedule_snapshots {
|
||||||
|
|
||||||
typeset FMRI=$1
|
typeset FMRI=$1
|
||||||
|
zfs_smf_props $1
|
||||||
# FIXME need work in here to actually validate the FMRI props
|
# FIXME need work in here to actually validate the FMRI props
|
||||||
typeset FILESYS=$(svcprop -p zfs/fs-name $FMRI)
|
typeset FILESYS="$fs_name"
|
||||||
typeset INTERVAL=$(svcprop -p zfs/interval $FMRI)
|
typeset INTERVAL="$interval"
|
||||||
typeset PERIOD=$(svcprop -p zfs/period $FMRI)
|
typeset PERIOD="$period"
|
||||||
typeset OFFSET=$(svcprop -p zfs/offset $FMRI)
|
typeset OFFSET="$offset"
|
||||||
typeset STATE=0
|
typeset STATE=0
|
||||||
|
|
||||||
typeset BACKUP=$(svcprop -p zfs/backup $FMRI)
|
typeset BACKUP="$backup"
|
||||||
typeset BACKUP_SAVE_CMD=$(svcprop -p zfs/backup $FMRI)
|
typeset BACKUP_SAVE_CMD="$backup_save_cmd"
|
||||||
|
|
||||||
case $BACKUP in
|
case $BACKUP in
|
||||||
'full' | 'incremental' )
|
'full' | 'incremental' )
|
||||||
@ -247,13 +267,14 @@ function unschedule_snapshots {
|
|||||||
function take_snapshot {
|
function take_snapshot {
|
||||||
# want this to be global, used by check_failure
|
# want this to be global, used by check_failure
|
||||||
FMRI=$1
|
FMRI=$1
|
||||||
|
zfs_smf_props $FMRI
|
||||||
|
|
||||||
typeset DATE=$(date +%F-%H${SEP}%M${SEP}%S)
|
typeset DATE=$(date +%F-%H${SEP}%M${SEP}%S)
|
||||||
typeset FILESYS=$(svcprop -p zfs/fs-name $FMRI)
|
typeset FILESYS=$fs_name
|
||||||
typeset KEEP=$(svcprop -p zfs/keep $FMRI)
|
typeset KEEP=$keep
|
||||||
typeset SNAP_CHILDREN=$(svcprop -p zfs/snapshot-children $FMRI)
|
typeset SNAP_CHILDREN=$snapshot_children
|
||||||
|
|
||||||
typeset BACKUP=$(svcprop -p zfs/backup $FMRI)
|
typeset BACKUP=$backup
|
||||||
|
|
||||||
typeset STATE=0
|
typeset STATE=0
|
||||||
|
|
||||||
@ -263,7 +284,7 @@ function take_snapshot {
|
|||||||
# returns the value '""' for the empty string to differentiate
|
# returns the value '""' for the empty string to differentiate
|
||||||
# between an unset property, and a set-but-empty property.
|
# between an unset property, and a set-but-empty property.
|
||||||
# Shocking, I know.
|
# Shocking, I know.
|
||||||
typeset LABEL="$(svcprop -p zfs/label $FMRI)"
|
typeset LABEL="$label"
|
||||||
|
|
||||||
# the "//" filesystem is special. We use it as a keyword
|
# the "//" filesystem is special. We use it as a keyword
|
||||||
# to determine whether to poll the ZFS "com.sun:auto-snapshot:${LABEL}"
|
# to determine whether to poll the ZFS "com.sun:auto-snapshot:${LABEL}"
|
||||||
@ -283,12 +304,12 @@ function take_snapshot {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# A flag for whether we're running in verbose mode or not
|
# A flag for whether we're running in verbose mode or not
|
||||||
VERBOSE="$(svcprop -p zfs/verbose $FMRI)"
|
VERBOSE="$verbose"
|
||||||
|
|
||||||
typeset SNAPNAME="${PREFIX}${LABEL}-${DATE}"
|
typeset SNAPNAME="${PREFIX}${LABEL}-${DATE}"
|
||||||
|
|
||||||
# Determine whether we should avoid scrubbing
|
# Determine whether we should avoid scrubbing
|
||||||
typeset AVOIDSCRUB=$(svcprop -p zfs/avoidscrub $FMRI)
|
typeset AVOIDSCRUB=$avoidscrub
|
||||||
|
|
||||||
# prune out the filesystems that are on pools currently being
|
# prune out the filesystems that are on pools currently being
|
||||||
# scrubbed or resilvered. There's a risk that a scrub/resilver
|
# scrubbed or resilvered. There's a risk that a scrub/resilver
|
||||||
@ -499,9 +520,8 @@ function take_backup { # filesystem backup-type label fmri
|
|||||||
svcadm refresh $FMRI
|
svcadm refresh $FMRI
|
||||||
fi
|
fi
|
||||||
|
|
||||||
typeset BACKUP_SAVE_CMD=$(svcprop -p zfs/backup-save-cmd $FMRI \
|
typeset BACKUP_SAVE_CMD="$(echo $backup_save_cmd | sed -e 's/\\//g')"
|
||||||
| sed -e 's/\\//g')
|
typeset SNAP_CHILDREN=$snapshot_children
|
||||||
typeset SNAP_CHILDREN=$(svcprop -p zfs/snapshot-children $FMRI)
|
|
||||||
typeset BACKUP_DATASETS=""
|
typeset BACKUP_DATASETS=""
|
||||||
|
|
||||||
# Determine how many datasets we have to backup
|
# Determine how many datasets we have to backup
|
||||||
@ -629,11 +649,13 @@ function is_scrubbing { # POOL SCRUBLIST
|
|||||||
# created above, where the argument is the FMRI containing properties we can
|
# created above, where the argument is the FMRI containing properties we can
|
||||||
# consult to in order to actually take the snapshot.
|
# consult to in order to actually take the snapshot.
|
||||||
|
|
||||||
|
zfs_smf_props $SMF_FMRI
|
||||||
|
export LOG=$(svcprop -p restarter/logfile $SMF_FMRI)
|
||||||
|
|
||||||
# $1 start | stop | an FMRI that we want to take snapshots of.
|
# $1 start | stop | an FMRI that we want to take snapshots of.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'start')
|
'start')
|
||||||
|
|
||||||
export LOG=$(svcprop -p restarter/logfile $SMF_FMRI)
|
|
||||||
schedule_snapshots $SMF_FMRI
|
schedule_snapshots $SMF_FMRI
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
result=$SMF_EXIT_OK
|
result=$SMF_EXIT_OK
|
||||||
@ -644,7 +666,6 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
'stop')
|
'stop')
|
||||||
export LOG=$(svcprop -p restarter/logfile $SMF_FMRI)
|
|
||||||
unschedule_snapshots $SMF_FMRI
|
unschedule_snapshots $SMF_FMRI
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
result=$SMF_EXIT_OK
|
result=$SMF_EXIT_OK
|
||||||
@ -662,7 +683,6 @@ case "$1" in
|
|||||||
|
|
||||||
case $SMF_FMRI in
|
case $SMF_FMRI in
|
||||||
svc:/*)
|
svc:/*)
|
||||||
export LOG=$(svcprop -p restarter/logfile $SMF_FMRI)
|
|
||||||
take_snapshot $SMF_FMRI
|
take_snapshot $SMF_FMRI
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
result=$SMF_EXIT_OK
|
result=$SMF_EXIT_OK
|
||||||
|
Loading…
Reference in New Issue
Block a user