0.11 work, part 1 - perf improvements for //, shell style, minor bugfixes

This commit is contained in:
Tim Foster 2008-07-14 00:47:24 +01:00
parent 89cb5a25ce
commit 15bbf270be
19 changed files with 304 additions and 318 deletions

View File

@ -1,15 +1,14 @@
NAME NAME
ZFS Automatic Snapshot SMF Service, version 0.10 ZFS Automatic Snapshot SMF Service, version 0.11
DESCRIPTION DESCRIPTION
This is a simple SMF service which you can configure to take automatic, This is a simple SMF service which can will take automatic,
scheduled snapshots of any given ZFS filesystem as well as perform simple scheduled snapshots of given ZFS filesystems and can perform simple
incremental or full backups of that filesystem. incremental or full backups of those filesystems.
Documentation for the service is contained in the manifest file, Documentation for the service is contained in the manifest file,
zfs-auto-snapshot.xml. zfs-auto-snapshot.xml.
@ -21,11 +20,10 @@ This GUI is installed in the GNOME menu under:
Administration -> Automatic Snapshots Administration -> Automatic Snapshots
We also bundle a simple GUI application, which will query the user for the We also bundle a simple GUI application, which will query the user for the
properties required, and will proceed to build an instance manifest. This properties required, and will then build an instance manifest. This
GUI is documented as part of the installation instructions below. GUI is documented as part of the installation instructions below.
INSTALLATION INSTALLATION
To install, as root, pkgadd TIMFauto-snapshot. This package now contains To install, as root, pkgadd TIMFauto-snapshot. This package now contains
@ -64,6 +62,10 @@ The properties each instance needs are:
command: command:
# zfs set com.sun:auto-snapshot:frequent=true tank/timf # zfs set com.sun:auto-snapshot:frequent=true tank/timf
When the "snap-children" property is set to true,
only locally-set filesystem properties are used to
determine which filesystems to snapshot -
property inheritance is not respected.
zfs/interval [ hours | days | months ] zfs/interval [ hours | days | months ]
@ -110,7 +112,7 @@ Usage: zfs-auto-snapshot-admin.sh [zfs filesystem name]
EXAMPLES EXAMPLES
The following shows me running it for the ZFS filesystem The following shows us running it for the ZFS filesystem
"tank/root_filesystem". "tank/root_filesystem".
timf@haiiro[593] ./zfs-auto-snapshot-admin.sh tank/root_filesystem timf@haiiro[593] ./zfs-auto-snapshot-admin.sh tank/root_filesystem
@ -144,5 +146,7 @@ http://blogs.sun.com/timf/entry/zfs_automatic_snapshot_service_logging
http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_8 http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_8
http://blogs.sun.com/timf/entry/zfs_automatic_for_the_people http://blogs.sun.com/timf/entry/zfs_automatic_for_the_people
http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_10 http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_10
http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_11
The ZFS Automatic Snapshot SMF Service is released under the terms of the CDDL. The ZFS Automatic Snapshot SMF Service is released under the terms of the CDDL.

View File

@ -4,7 +4,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='tank-timf-torrent,foo' enabled='false' > <instance name='tank-timf-torrent,foo' enabled='false' >
@ -12,7 +12,6 @@
<exec_method <exec_method
type='method' type='method'
name='start' name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' /> timeout_seconds='10' />
<exec_method <exec_method

View File

@ -63,8 +63,19 @@ PREFIX="zfs-auto-snap"
# clients can get confused by colons. Who knew? # clients can get confused by colons. Who knew?
SEP=":" SEP=":"
# This variable gets set to the restarter/logfile property
# whenever we have $FMRI defined. Used by the print_log and
# print_note functions below for all output, it's definied
# by the schedule_snapshots take_snapshots and unschedule_snapshots
# methods.
LOG=""
# Determine whether this invocation of the script can use
# the recursive snapshot feature in some versions of ZFS.
# a null string in this variable says we don't.
HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r')
# 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.
@ -84,9 +95,9 @@ function schedule_snapshots {
case $BACKUP in case $BACKUP in
'full' | 'incremental' ) 'full' | 'incremental' )
if [ -z "${BACKUP_SAVE_CMD}" ] if [ -z "${BACKUP_SAVE_CMD}" ] ; then
then check_failure 1 \
check_failure 1 "Backup requested, but no backup command specified." "Backup requested, but no backup command specified."
fi fi
;; ;;
esac esac
@ -94,8 +105,7 @@ function schedule_snapshots {
# for now, we're forcing the offset to be 0 seconds. # for now, we're forcing the offset to be 0 seconds.
typeset OFFSET=0 typeset OFFSET=0
if [ "$FILESYS" != "//" ] if [ "$FILESYS" != "//" ] ; then
then
# validate the filesystem # validate the filesystem
zfs list $FILESYS 2>&1 1> /dev/null zfs list $FILESYS 2>&1 1> /dev/null
check_failure $? "ZFS filesystem does not exist!" check_failure $? "ZFS filesystem does not exist!"
@ -108,8 +118,7 @@ function schedule_snapshots {
# finally, check our status before we return # finally, check our status before we return
STATE=$(svcprop -p restarter/state $FMRI) STATE=$(svcprop -p restarter/state $FMRI)
if [ "${STATE}" == "maintenance" ] if [ "${STATE}" == "maintenance" ] ; then
then
STATE=1 STATE=1
else else
STATE=0 STATE=0
@ -166,14 +175,12 @@ function add_cron_job { # $INTERVAL $PERIOD $OFFSET $FMRI
# at the same time (without requiring users to explicitly state dependencies # at the same time (without requiring users to explicitly state dependencies
# and change them each time new instances are added) # and change them each time new instances are added)
# This isn't perfect (eg. if someone else if running crontab at the # This isn't perfect (eg. if someone else is running crontab at the
# same time as us, we'll fail) but it'll do for now. # same time as us, we'll fail) but it'll do for now.
LOCK_OWNED="false" LOCK_OWNED="false"
while [ "$LOCK_OWNED" == "false" ] while [ "$LOCK_OWNED" == "false" ] ; do
do mkdir /tmp/zfs-auto-snapshot-lock > /dev/null 2>&1
mkdir /tmp/zfs-auto-snapshot-lock if [ $? -eq 0 ] ; then
if [ $? -eq 0 ]
then
LOCK_OWNED=true LOCK_OWNED=true
else else
sleep 1 sleep 1
@ -182,8 +189,12 @@ function add_cron_job { # $INTERVAL $PERIOD $OFFSET $FMRI
# adding a cron job is essentially just looking for an existing entry, # adding a cron job is essentially just looking for an existing entry,
# removing it, and appending a new one. Neato. # removing it, and appending a new one. Neato.
crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" > /tmp/saved-crontab.$$ crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" \
echo "${ENTRY} /lib/svc/method/zfs-auto-snapshot $FMRI" >> /tmp/saved-crontab.$$ > /tmp/saved-crontab.$$
echo "${ENTRY} /lib/svc/method/zfs-auto-snapshot $FMRI" \
>> /tmp/saved-crontab.$$
crontab /tmp/saved-crontab.$$ crontab /tmp/saved-crontab.$$
check_failure $? "Unable to add cron job!" check_failure $? "Unable to add cron job!"
@ -203,18 +214,18 @@ function unschedule_snapshots {
# See notes on $LOCK_OWNED variable in function add_cron_job # See notes on $LOCK_OWNED variable in function add_cron_job
LOCK_OWNED="false" LOCK_OWNED="false"
while [ "$LOCK_OWNED" == "false" ] while [ "$LOCK_OWNED" == "false" ]; do
do mkdir /tmp/zfs-auto-snapshot-lock > /dev/null 2>&1
mkdir /tmp/zfs-auto-snapshot-lock if [ $? -eq 0 ] ; then
if [ $? -eq 0 ]
then
LOCK_OWNED=true LOCK_OWNED=true
else else
sleep 1 sleep 1
fi fi
done done
crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" > /tmp/saved-crontab.$$ crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" \
> /tmp/saved-crontab.$$
crontab /tmp/saved-crontab.$$ crontab /tmp/saved-crontab.$$
check_failure $? "Unable to unschedule snapshots for $FMRI" check_failure $? "Unable to unschedule snapshots for $FMRI"
@ -223,8 +234,7 @@ function unschedule_snapshots {
# finally, check our status before we return # finally, check our status before we return
STATE=$(svcprop -p restarter/state $FMRI) STATE=$(svcprop -p restarter/state $FMRI)
if [ "${STATE}" == "maintenance" ] if [ "${STATE}" == "maintenance" ] ; then
then
STATE=1 STATE=1
else else
STATE=0 STATE=0
@ -232,12 +242,11 @@ function unschedule_snapshots {
} }
# This function actually takes the snapshot of the filesystem. This is what # This function actually takes the snapshot of the filesystem.
# really does the work. We name snapshots based on a standard time format
# $1 is assumed to be a valid FMRI # $1 is assumed to be a valid FMRI
function take_snapshot { function take_snapshot {
# want this to be global, used by check_failure
typeset FMRI=$1 FMRI=$1
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=$(svcprop -p zfs/fs-name $FMRI)
@ -245,8 +254,8 @@ function take_snapshot {
typeset SNAP_CHILDREN=$(svcprop -p zfs/snapshot-children $FMRI) typeset SNAP_CHILDREN=$(svcprop -p zfs/snapshot-children $FMRI)
typeset BACKUP=$(svcprop -p zfs/backup $FMRI) typeset BACKUP=$(svcprop -p zfs/backup $FMRI)
typeset STATE=0
typeset STATE=0
# an identifier allows us to setup multiple snapshot schedules # an identifier allows us to setup multiple snapshot schedules
# per filesystem - so we append a <sep><label> token if the user has # per filesystem - so we append a <sep><label> token if the user has
@ -256,21 +265,18 @@ function take_snapshot {
# Shocking, I know. # Shocking, I know.
typeset LABEL="$(svcprop -p zfs/label $FMRI)" typeset LABEL="$(svcprop -p zfs/label $FMRI)"
# 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}"
# user property which specifies which datasets should be snapshotted # user property which specifies which datasets should be snapshotted
# and under which "label" - a set of default service instances that # and under which "label" - a set of default service instances that
# snapshot at defined periods (daily, weekly, monthly, every 15 mins) # snapshot at defined periods (daily, weekly, monthly, every 15 mins)
if [ "$FILESYS" == "//" ] if [ "$FILESYS" == "//" ] ; then
then FILESYS=$(get_snapshot_datasets $LABEL $SNAP_CHILDREN)
FILESYS=$(get_snapshot_datasets $LABEL)
else else
FILESYS=$FILESYS FILESYS=$FILESYS
fi fi
if [ "$LABEL" != "\"\"" ] if [ "$LABEL" != "\"\"" ] ; then
then
LABEL="${SEP}${LABEL}" LABEL="${SEP}${LABEL}"
else else
LABEL="" LABEL=""
@ -284,24 +290,20 @@ function take_snapshot {
# Determine whether we should avoid scrubbing # Determine whether we should avoid scrubbing
typeset AVOIDSCRUB=$(svcprop -p zfs/avoidscrub $FMRI) typeset AVOIDSCRUB=$(svcprop -p zfs/avoidscrub $FMRI)
# 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
# will be started just after this check completes, but there's # will be started just after this check completes, but there's
# also the risk that a running scrub will complete just after this # also the risk that a running scrub will complete just after this
# check. Life's hard. # check. Life's hard.
if [ "$AVOIDSCRUB" == "true" ] if [ "$AVOIDSCRUB" == "true" ] ; then
then
# a cache of the pools that are known not to be scrubbing # a cache of the pools that are known not to be scrubbing
NOSCRUBLIST="" NOSCRUBLIST=""
# Create a list of filesystems scheduled for snapshots # Create a list of filesystems scheduled for snapshots
# that are *not* on pools that are being scrubbed/resilvered # that are *not* on pools that are being scrubbed/resilvered
for fs in $FILESYS for fs in $FILESYS ; do
do
POOL=$(echo $fs | cut -d/ -f1) POOL=$(echo $fs | cut -d/ -f1)
if is_scrubbing $POOL "$NOSCRUBLIST" if is_scrubbing $POOL "$NOSCRUBLIST" ; then
then
print_log "Pool containing $fs is being scrubbed/resilvered." print_log "Pool containing $fs is being scrubbed/resilvered."
print_log "Not taking snapshots for $fs." print_log "Not taking snapshots for $fs."
else else
@ -313,47 +315,34 @@ function take_snapshot {
fi fi
# walk each of the filesystems specified # walk each of the filesystems specified
for fs in $FILESYS for fs in $FILESYS ; do
do
# Ok, now say cheese! If we're taking recursive snapshots, # Ok, now say cheese! If we're taking recursive snapshots,
# walk through the children, destroying old ones if required. # walk through the children, destroying old ones if required.
if [ "${SNAP_CHILDREN}" == "true" ] if [ "${SNAP_CHILDREN}" == "true" ] ; then
then
# check if we have recursive snapshot capability, seeing if [ -z "${HAS_RECURSIVE}" ] ; then
# a null string in this variable says we don't. for child in $(zfs list -r -H -o name -t filesystem,volume $fs) ; do
HAS_RECURSIVE=$(zfs snapshot 2>&1 | fgrep -e '-r')
for child in $(zfs list -r -H -o name -t filesystem,volume $fs)
do
destroy_older_snapshots $child $KEEP $LABEL destroy_older_snapshots $child $KEEP $LABEL
if [ -z "${HAS_RECURSIVE}" ]
then
print_note "Taking snapshot $child@$SNAPNAME" print_note "Taking snapshot $child@$SNAPNAME"
zfs snapshot $child@$SNAPNAME zfs snapshot $child@$SNAPNAME
check_failure $? "Unable to take snapshot $child@$SNAPNAME." check_failure $? "Unable to take snapshot $child@$SNAPNAME."
fi
done done
# take the recursive snapshots if we have the ability else
if [ -n "${HAS_RECURSIVE}" ] destroy_older_snapshots $fs $KEEP $LABEL $HAS_RECURSIVE
then
print_note "Taking recursive snapshot $fs@$SNAPNAME" print_note "Taking recursive snapshot $fs@$SNAPNAME"
zfs snapshot -r $fs@$SNAPNAME zfs snapshot -r $fs@$SNAPNAME
check_failure $? "Unable to take recursive snapshots $fs@$SNAPNAME." check_failure $? "Unable to take recursive snapshots of $fs@$SNAPNAME."
fi fi
else else
destroy_older_snapshots $fs $KEEP $LABEL destroy_older_snapshots $fs $KEEP $LABEL
print_note "Taking snapshot $fs@$SNAPNAME" print_note "Taking snapshot $fs@$SNAPNAME"
zfs snapshot $fs@$SNAPNAME zfs snapshot $fs@$SNAPNAME
check_failure $? "Unable to take snapshot $fs@$SNAPNAME." check_failure $? "Unable to take snapshot $fs@$SNAPNAME."
fi fi
# If the user has asked for backups, go ahead and do this. # If the user has asked for backups, go ahead and do this.
if [ "${BACKUP}" != "none" ] if [ "${BACKUP}" != "none" ] ; then
then
take_backup $fs $BACKUP "$LABEL" $FMRI take_backup $fs $BACKUP "$LABEL" $FMRI
check_failure $? "Unable to backup filesystem $fs using \ check_failure $? "Unable to backup filesystem $fs using \
$BACKUP backup strategy." $BACKUP backup strategy."
@ -362,8 +351,7 @@ function take_snapshot {
done done
# finally, check our status before we return # finally, check our status before we return
STATE=$(svcprop -p restarter/state $FMRI) STATE=$(svcprop -p restarter/state $FMRI)
if [ "${STATE}" == "maintenance" ] if [ "${STATE}" == "maintenance" ] ; then
then
STATE=1 STATE=1
else else
STATE=0 STATE=0
@ -383,23 +371,26 @@ function destroy_older_snapshots {
typeset FILESYS=$1 typeset FILESYS=$1
typeset COUNTER=$2 typeset COUNTER=$2
typeset LABEL=$3 typeset LABEL=$3
typeset HAS_RECURSIVE=$4
if [ "${COUNTER}" == "all" ] if [ "${COUNTER}" == "all" ] ; then
then
return 0 return 0
fi fi
COUNTER=$(($COUNTER - 1)) if [ -n "${HAS_RECURSIVE}" ] ; then
typeset RECURSIVE="-r"
fi
COUNTER=$(($COUNTER - 1))
# walk through the snapshots, newest first, destroying older ones # walk through the snapshots, newest first, destroying older ones
for snapshot in $(zfs list -r -t snapshot -H -o name $FILESYS \ for snapshot in $(zfs list -r -t snapshot -H -o name $FILESYS \
| grep "$FILESYS@${PREFIX}${LABEL}" | sort -r) | grep "$FILESYS@${PREFIX}${LABEL}" | sort -r) ; do
do
if [ $COUNTER -le 0 ] if [ $COUNTER -le 0 ] ; then
then
# using print_note, as this checks our $VERBOSE flag # using print_note, as this checks our $VERBOSE flag
print_note "$snapshot being destroyed as per retention policy." print_note "$snapshot being destroyed ${RECURSIVE} as per \
zfs destroy $snapshot retention policy."
zfs destroy ${RECURSIVE} $snapshot
check_failure $? "Unable to destroy $snapshot" check_failure $? "Unable to destroy $snapshot"
else else
# don't destroy this one # don't destroy this one
@ -418,8 +409,7 @@ function check_failure { # integer exit status, error message to display
typeset RESULT=$1 typeset RESULT=$1
typeset ERR_MSG=$2 typeset ERR_MSG=$2
if [ $RESULT -ne 0 ] if [ $RESULT -ne 0 ] ; then
then
print_log "Error: $ERR_MSG" print_log "Error: $ERR_MSG"
print_log "Moving service $FMRI to maintenance mode." print_log "Moving service $FMRI to maintenance mode."
svcadm mark maintenance $FMRI svcadm mark maintenance $FMRI
@ -431,18 +421,19 @@ function check_failure { # integer exit status, error message to display
# A function we use to emit output. Right now, this goes to syslog via logger(1) # A function we use to emit output. Right now, this goes to syslog via logger(1)
# but it would be much nicer to be able to print it to the svc log file for # but it would be much nicer to be able to print it to the svc log file for
# each individual service instance - tricky because we're being called from # each individual service instance - tricky because we're being called from
# cron, most of the time and are detached from smf. # cron, most of the time and are detached from smf. Working around this by
# appending to the $LOG file
function print_log { # message to display function print_log { # message to display
logger -t zfs-auto-snap -p daemon.notice $* logger -t zfs-auto-snap -p daemon.notice $*
echo $(date) $* >> $LOG
} }
# Another function to emit output, this time checking to see if the # Another function to emit output, this time checking to see if the
# user has set the service into verbose mode, otherwise, we print nothing # user has set the service into verbose mode, otherwise, we print nothing
function print_note { # mesage to display function print_note { # mesage to display
if [ "$VERBOSE" == "true" ] if [ "$VERBOSE" == "true" ] ; then
then
logger -t zfs-auto-snap -p daemon.notice $* logger -t zfs-auto-snap -p daemon.notice $*
echo $(date) $* >> $LOG
fi fi
} }
@ -459,8 +450,7 @@ function get_divisor { # start period, end period, width of period
typeset RANGE=$START typeset RANGE=$START
typeset JUMP=$(( $RANGE + $WIDTH )) typeset JUMP=$(( $RANGE + $WIDTH ))
while [ $JUMP -le $END ] while [ $JUMP -le $END ] ; do
do
RANGE="$RANGE,$JUMP" RANGE="$RANGE,$JUMP"
JUMP=$(( $JUMP + $WIDTH )) JUMP=$(( $JUMP + $WIDTH ))
done done
@ -515,8 +505,7 @@ function take_backup { # filesystem backup-type label fmri
typeset BACKUP_DATASETS="" typeset BACKUP_DATASETS=""
# Determine how many datasets we have to backup # Determine how many datasets we have to backup
if [ "$SNAP_CHILDREN" == "true" ] if [ "$SNAP_CHILDREN" == "true" ] ; then
then
BACKUP_DATASETS=$(zfs list -r -H -o name -t filesystem,volume $FILESYS) BACKUP_DATASETS=$(zfs list -r -H -o name -t filesystem,volume $FILESYS)
else else
# only one dataset to worry about here. # only one dataset to worry about here.
@ -524,8 +513,7 @@ function take_backup { # filesystem backup-type label fmri
fi fi
# loop through the datasets, backing up each one. # loop through the datasets, backing up each one.
for dataset in $BACKUP_DATASETS for dataset in $BACKUP_DATASETS ; do
do
# An initial check of the input parameters, to see how we should proceed # An initial check of the input parameters, to see how we should proceed
case $BACKUP in case $BACKUP in
@ -580,12 +568,21 @@ function take_backup { # filesystem backup-type label fmri
} }
# Get a list of filesystem we should snapshot # Get a list of filesystem we should snapshot. If snap_children is "true"
function get_snapshot_datasets { #LABEL # then we don't list children that inherit the parent's property - we just look
# for locally set properties, and let "zfs snapshot -r" snapshot the children.
function get_snapshot_datasets { #LABEL #SNAP_CHILDREN
typeset LABEL=$1 typeset LABEL=$1
typeset FS=$(zfs list -t filesystem -o name,com.sun:auto-snapshot:$LABEL \ typeset SNAP_CHILDREN=$2
if [ "${SNAP_CHILDREN}" = "true" ] ; then
typeset FS=$(zfs get com.sun:auto-snapshot:$LABEL \
| grep local | grep true | awk '{print $1}')
else
typeset FS=$(zfs list -t filesystem,volume \
-o name,com.sun:auto-snapshot:$LABEL \
| grep true | awk '{print $1}') | grep true | awk '{print $1}')
fi
echo "$FS" echo "$FS"
} }
@ -608,14 +605,12 @@ function is_scrubbing { # POOL SCRUBLIST
# the pool name in a known list of pools that were not scrubbing # the pool name in a known list of pools that were not scrubbing
# the last time we checked. # the last time we checked.
echo "$NOSCRUBLIST" | grep "$POOL " > /dev/null echo "$NOSCRUBLIST" | grep "$POOL " > /dev/null
if [ $? -eq 0 ] if [ $? -eq 0 ] ; then
then
return 1 return 1
fi fi
SCRUBBING=$(env LC_ALL=C zpool status $POOL | grep " in progress") SCRUBBING=$(env LC_ALL=C zpool status $POOL | grep " in progress")
if [ -z "$SCRUBBING" ] if [ -z "$SCRUBBING" ] ; then
then
return 1 return 1
else else
return 0 return 0
@ -638,9 +633,9 @@ function is_scrubbing { # POOL SCRUBLIST
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 ] if [ $? -eq 0 ] ; then
then
result=$SMF_EXIT_OK result=$SMF_EXIT_OK
else else
print_log "Problem taking snapshots for $SMF_FMRI" print_log "Problem taking snapshots for $SMF_FMRI"
@ -649,9 +644,9 @@ case "$1" in
;; ;;
'stop') 'stop')
export LOG=$(svcprop -p restarter/logfile $SMF_FMRI)
unschedule_snapshots $SMF_FMRI unschedule_snapshots $SMF_FMRI
if [ $? -eq 0 ] if [ $? -eq 0 ] ; then
then
result=$SMF_EXIT_OK result=$SMF_EXIT_OK
else else
print_log "Problem taking snapshots for $SMF_FMRI" print_log "Problem taking snapshots for $SMF_FMRI"
@ -667,9 +662,9 @@ 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 ] if [ $? -eq 0 ] ; then
then
result=$SMF_EXIT_OK result=$SMF_EXIT_OK
else else
result=$SMF_EXIT_ERR_FATAL result=$SMF_EXIT_ERR_FATAL

View File

@ -9,7 +9,7 @@ PKG=TIMFauto-snapshot
NAME=ZFS Automatic Snapshot Service NAME=ZFS Automatic Snapshot Service
ARCH=all ARCH=all
BASEDIR=/ BASEDIR=/
VERSION=0.10 VERSION=0.11
MAXINST=1 MAXINST=1
CATEGORY=application CATEGORY=application
DESC=Takes automatic snapshots of ZFS filesystems on a periodic basis. DESC=Takes automatic snapshots of ZFS filesystems on a periodic basis.

View File

@ -37,10 +37,12 @@ FILES="auto-snapshot-daily.xml auto-snapshot-monthly.xml auto-snapshot-frequ
for manifest in $FILES for manifest in $FILES
do do
echo Importing $manifest
/usr/sbin/svccfg import /var/svc/manifest/system/filesystem/$manifest /usr/sbin/svccfg import /var/svc/manifest/system/filesystem/$manifest
done done
for fmri in $FMRIS for fmri in $FMRIS
do do
echo Enabling $fmri
/usr/sbin/svcadm enable $fmri /usr/sbin/svcadm enable $fmri
done done

View File

@ -31,13 +31,10 @@ DEFAULT=svc:/system/filesystem/zfs/auto-snapshot:default
FMRIS="svc:/system/filesystem/zfs/auto-snapshot:frequent svc:/system/filesystem/zfs/auto-snapshot:hourly svc:/system/filesystem/zfs/auto-snapshot:daily svc:/system/filesystem/zfs/auto-snapshot:weekly svc:/system/filesystem/zfs/auto-snapshot:monthly" FMRIS="svc:/system/filesystem/zfs/auto-snapshot:frequent svc:/system/filesystem/zfs/auto-snapshot:hourly svc:/system/filesystem/zfs/auto-snapshot:daily svc:/system/filesystem/zfs/auto-snapshot:weekly svc:/system/filesystem/zfs/auto-snapshot:monthly"
for fmri in $FMRIS $DEFAULT for fmri in $FMRIS $DEFAULT ; do
do STATE=$(/usr/bin/svcs -H -o state $fmri)
/usr/sbin/svcadm disable $fmri if [ "$STATE" = "online" ] ; then
while [ "$STATE" != "disabled" ] /usr/sbin/svcadm disable -s $fmri
do fi
sleep 1
STATE=`/usr/bin/svcs -H -o state $fmri`
done
/usr/sbin/svccfg delete $fmri /usr/sbin/svccfg delete $fmri
done done

View File

@ -17,7 +17,7 @@ d none usr 0755 root sys
d none usr/share 0755 root sys d none usr/share 0755 root sys
d none usr/share/applications 0755 root other d none usr/share/applications 0755 root other
f none usr/share/applications/automatic-snapshot.desktop 0644 root bin f none usr/share/applications/automatic-snapshot.desktop 0644 root bin
d none usr/bin 0755 root sys d none usr/bin 0755 root bin
f none usr/bin/zfs-auto-snapshot-admin.sh 0755 root sys f none usr/bin/zfs-auto-snapshot-admin.sh 0755 root sys
d none lib 0755 root bin d none lib 0755 root bin
d none lib/svc 0755 root bin d none lib/svc 0755 root bin

View File

@ -7,7 +7,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='space-archive' enabled='false' > <instance name='space-archive' enabled='false' >

View File

@ -9,7 +9,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='space-timf,backup' enabled='false' > <instance name='space-timf,backup' enabled='false' >

View File

@ -8,7 +8,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='space-timf,daily' enabled='false' > <instance name='space-timf,daily' enabled='false' >

View File

@ -8,7 +8,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='space-timf,frequent' enabled='false' > <instance name='space-timf,frequent' enabled='false' >

View File

@ -8,7 +8,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='space-timf,monthly' enabled='false' > <instance name='space-timf,monthly' enabled='false' >

View File

@ -8,7 +8,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
<instance name='tank-rootfs' enabled='false' > <instance name='tank-rootfs' enabled='false' >

View File

@ -4,12 +4,13 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- This is one of the default instances that comes with the <!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked ZFS Automatic Snapshot SMF Service. It recursively snapshots all
with the ZFS User Property com.sun:auto-snapshot:daily=true daily, filesystems marked with the ZFS User Property
and keeps 31 of these snapshots into the past. com.sun:auto-snapshot:daily=true daily, and keeps 31 of these
snapshots into the past.
--> -->
<create_default_instance enabled='false' /> <create_default_instance enabled='false' />
@ -45,7 +46,7 @@
override="true"/> override="true"/>
<propval name="keep" type="astring" value="31" <propval name="keep" type="astring" value="31"
override="true"/> override="true"/>
<propval name="snapshot-children" type="boolean" value="false" <propval name="snapshot-children" type="boolean" value="true"
override="true"/> override="true"/>
<propval name="backup" type="astring" value="none" <propval name="backup" type="astring" value="none"

View File

@ -4,11 +4,12 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- This is one of the default instances that comes with the <!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked ZFS Automatic Snapshot SMF Service. It recursively snapshots all
with the ZFS User Property com.sun:auto-snapshot:frequent=true every filesystems marked with the ZFS User Property
com.sun:auto-snapshot:frequent=true every
15 minutes, and keeps 4 of these snapshots into the past. 15 minutes, and keeps 4 of these snapshots into the past.
--> -->
@ -45,7 +46,7 @@
override="true"/> override="true"/>
<propval name="keep" type="astring" value="4" <propval name="keep" type="astring" value="4"
override="true"/> override="true"/>
<propval name="snapshot-children" type="boolean" value="false" <propval name="snapshot-children" type="boolean" value="true"
override="true"/> override="true"/>
<propval name="backup" type="astring" value="none" <propval name="backup" type="astring" value="none"

View File

@ -4,11 +4,12 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- This is one of the default instances that comes with the <!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked ZFS Automatic Snapshot SMF Service. It recursively s
with the ZFS User Property com.sun:auto-snapshot:hourly=true hourly, snapshots all filesystems marked with the ZFS User Property
com.sun:auto-snapshot:hourly=true hourly,
and keeps 24 of these snapshots into the past. and keeps 24 of these snapshots into the past.
--> -->
@ -45,7 +46,7 @@
override="true"/> override="true"/>
<propval name="keep" type="astring" value="24" <propval name="keep" type="astring" value="24"
override="true"/> override="true"/>
<propval name="snapshot-children" type="boolean" value="false" <propval name="snapshot-children" type="boolean" value="true"
override="true"/> override="true"/>
<propval name="backup" type="astring" value="none" <propval name="backup" type="astring" value="none"

View File

@ -4,11 +4,12 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- This is one of the default instances that comes with the <!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked ZFS Automatic Snapshot SMF Service. It recursively snapshots
with the ZFS User Property com.sun:auto-snapshot:monthly=true monthly, all filesystems marked with the ZFS User Property
com.sun:auto-snapshot:monthly=true monthly,
and keeps 12 of these snapshots into the past. and keeps 12 of these snapshots into the past.
--> -->
@ -45,7 +46,7 @@
override="true"/> override="true"/>
<propval name="keep" type="astring" value="12" <propval name="keep" type="astring" value="12"
override="true"/> override="true"/>
<propval name="snapshot-children" type="boolean" value="false" <propval name="snapshot-children" type="boolean" value="true"
override="true"/> override="true"/>
<propval name="backup" type="astring" value="none" <propval name="backup" type="astring" value="none"

View File

@ -4,11 +4,12 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- This is one of the default instances that comes with the <!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked ZFS Automatic Snapshot SMF Service. It recursively snapshots all
with the ZFS User Property com.sun:auto-snapshot:weekly=true weekly, filesystems marked with the ZFS User Property
com.sun:auto-snapshot:weekly=true weekly,
and keeps 4 of these snapshots into the past. and keeps 4 of these snapshots into the past.
--> -->
@ -45,7 +46,7 @@
override="true"/> override="true"/>
<propval name="keep" type="astring" value="4" <propval name="keep" type="astring" value="4"
override="true"/> override="true"/>
<propval name="snapshot-children" type="boolean" value="false" <propval name="snapshot-children" type="boolean" value="true"
override="true"/> override="true"/>
<propval name="backup" type="astring" value="none" <propval name="backup" type="astring" value="none"

View File

@ -22,7 +22,7 @@
CDDL HEADER END CDDL HEADER END
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Copyright 2008 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms. Use is subject to license terms.
--> -->
@ -32,7 +32,7 @@
<service <service
name='system/filesystem/zfs/auto-snapshot' name='system/filesystem/zfs/auto-snapshot'
type='service' type='service'
version='0.10'> version='0.11'>
<!-- no point in being able to take snapshots if we don't have a fs --> <!-- no point in being able to take snapshots if we don't have a fs -->
<dependency <dependency
@ -58,7 +58,6 @@
<!-- the properties we expect that any instance will define <!-- the properties we expect that any instance will define
they being : they being :
fs-name : The name of the filesystem we want to snapshot. fs-name : The name of the filesystem we want to snapshot.
The special filesystem name "//" indicates we should The special filesystem name "//" indicates we should
look at the com.sun:auto-snapshot:<label> ZFS user look at the com.sun:auto-snapshot:<label> ZFS user
@ -202,32 +201,17 @@
This service provides system support for taking automatic snapshots of ZFS This service provides system support for taking automatic snapshots of ZFS
filesystems. filesystems.
In order to use this service, you must create a service instance per set of In order to use this service, you must create a service instance per set of automatic snapshots you want to take.
automatic snapshots you want to take.
The on starting a service instance, a cron job corresponding to the properties The on starting a service instance, a cron job corresponding to the properties set in the instance is created on the host. This cron job will regularly take snapshots of the specified ZFS filesystem.
set in the instance is created on the host. This cron job will regularly take
snapshots of the specified ZFS filesystem.
On stopping the service, that cron job is removed. On stopping the service, that cron job is removed.
We also have the ability to perform backups, done using the "zfs send" command. We also have the ability to perform backups, done using the "zfs send" command. A property set in the service called "backup-save-cmd" can be configured as the command used to save the backup stream. See the zfs(1M) man page for an example. The backups can be either "full" backups, or "incremental" backups - for each incremental backup, a full backup must be configured first. If for some reason an incremental backup fails, a full backup is performed instead.
A property set in the service called "backup-save-cmd" can be configured as the
command used to save the backup stream. See the zfs(1M) man page for an example.
The backups can be either "full" backups, or "incremental" backups - for each
incremental backup, a full backup must be configured first. If for some reason
an incremental backup fails, a full backup is performed instead.
By default, snapshots will not be taken of any datasets resident on pools that By default, snapshots will not be taken of any datasets resident on pools that are currently being scrubbed or resilvered. This can behaviour can be changed using the zfs/avoid scrub service property.
are currently being scrubbed or resilvered. This can behaviour can be changed
using the zfs/avoid scrub service property.
Care should be taken when configuring backups to ensure that the time
granularity of the cron job is sufficient to allow the backup to complete
between invocations of each backup. We perform locking to ensure that two
backups of the same filesystem cannot run simultaneously, but will move the
service into "maintenance" state should this occur.
Care should be taken when configuring backups to ensure that the time granularity of the cron job is sufficient to allow the backup to complete between invocations of each backup. We perform locking to ensure that two backups of the same filesystem cannot run simultaneously, but will move the service into "maintenance" state should this occur.
</loctext> </loctext>
</description> </description>
</template> </template>