Version 0.7

This commit is contained in:
Tim Foster 2008-06-29 18:34:18 +01:00
parent acca7a30a3
commit a84d1e0650
12 changed files with 441 additions and 40 deletions

View File

@ -1,7 +1,7 @@
NAME
ZFS Automatic Snapshot SMF Service, version 0.6
ZFS Automatic Snapshot SMF Service, version 0.7
@ -84,7 +84,10 @@ you can now import the manifest for this instance, using the command :
then issue the command :
# svcadm enable svc:/system/filesystem/zfs/auto-snapshot:tank-root_filesystem
You can see what work will be done by checking your crontab.
You can see what work will be done by checking your crontab. As of version
0.7, all logging from the service is done from the method script using
the print_log function, which uses logger(1) to send message to syslogd(1M)
at priority level "daemon.notice".
SEE ALSO
@ -98,5 +101,6 @@ http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_smf_service
http://blogs.sun.com/timf/entry/and_also_for_s10u2_zfs
http://blogs.sun.com/timf/entry/smf_philosophy_more_on_zfs
http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_now_with
http://blogs.sun.com/timf/entry/zfs_automatic_snapshot_service_logging
The ZFS Automatic Snapshot SMF Service is released under the terms of the CDDL.

View File

@ -4,7 +4,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.6'>
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,10mins' enabled='false' >

View File

@ -292,7 +292,7 @@ function destroy_older_snapshots {
do
if [ $COUNTER -le 0 ]
then
echo "$snapshot being destroyed as per retention policy."
print_log "$snapshot being destroyed as per retention policy."
zfs destroy $snapshot
check_failure $? "Unable to destroy $snapshot"
else
@ -309,19 +309,29 @@ function destroy_older_snapshots {
#
function check_failure { # integer exit status, error message to display
typeset RESULT=$1
typeset ERR_MSG=$2
typeset RESULT=$1
typeset ERR_MSG=$2
if [ $RESULT -ne 0 ]
then
echo "Error: $ERR_MSG"
echo "Moving service $FMRI to maintenance mode."
svcadm mark maintenance $FMRI
fi
if [ $RESULT -ne 0 ]
then
print_log "Error: $ERR_MSG"
print_log "Moving service $FMRI to maintenance mode."
svcadm mark maintenance $FMRI
fi
}
# 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
# each individual service instance - tricky because we're being called from
# cron, most of the time and are detached from smf.
function print_log { # message to display
logger -t zfs-auto-snap -p daemon.notice $*
}
# Given a range start, end and width of period, return a comma
# separated string of numbers within that range and conforming to
# that period. This isn't ideal, but it'll do for now.
@ -363,16 +373,18 @@ function take_backup { # filesystem backup-type label fmri
then
# Unable to perform this backup due to an existing backup being
# executed for this dataset. This would result in moving the
# service to maintenance mode if we're doing incrementals, but
# it's not so serious for full backups.
echo "Unable to backup $FILESYS: $LOCK."
# service to maintenance mode if we're doing incrementals, since
# missing an incremental backup will result in the user being unable
# to restore future incremental backups. This isn't so serious for
# full backups.
print_log "Unable to backup $FILESYS: $LOCK."
if [ "$BACKUP" == "incremental" ]
then
echo "A lock prevented us from performing an incremental backup."
print_log "A lock prevented us from performing an incremental backup."
return 1
else
echo "Full backup not completed for $FMRI on $(date)."
print_log "Full backup not completed for $FMRI."
return 0
fi
else
@ -413,7 +425,7 @@ function take_backup { # filesystem backup-type label fmri
if [ "$PREV_SNAP" == "$LAST_SNAP" ]
then
echo "Previous snap not found of $dataset, taking full backup"
print_log "Previous snap not found of $dataset, taking full backup."
BACKUP="full"
fi
;;
@ -471,7 +483,7 @@ case "$1" in
then
result=$SMF_EXIT_OK
else
echo "Uhho, something went wrong with $SMF_FMRI"
print_log "Problem taking snapshots for $SMF_FMRI"
result=$SMF_EXIT_ERR_FATAL
fi
;;
@ -482,7 +494,7 @@ case "$1" in
then
result=$SMF_EXIT_OK
else
echo "Uhho something went wrong with $SMF_FMRI"
print_log "Problem taking snapshots for $SMF_FMRI"
result=$SMF_EXIT_ERR_FATAL
fi
;;
@ -493,23 +505,24 @@ case "$1" in
SMF_FMRI=$1
# are we being called with the correct argument (an FMRI) ?
echo $SMF_FMRI | grep "^svc:/"
if [ $? -eq 0 ]
then
take_snapshot $SMF_FMRI
if [ $? -eq 0 ]
then
result=$SMF_EXIT_OK
else
result=$SMF_EXIT_ERR_FATAL
fi
else
echo "Usage from SMF : zfs-auto-snapshot [start | stop]"
echo "Usage from cron: zfs-auto-snapshot svc:/system/filesystem/zfs/auto-snapshot:instance"
fi
case $SMF_FMRI in
svc:/*)
take_snapshot $SMF_FMRI
if [ $? -eq 0 ]
then
result=$SMF_EXIT_OK
else
result=$SMF_EXIT_ERR_FATAL
fi
;;
*)
# not logging these messages - we're assuming a curious
# user has run the script from the command line.
echo "Usage from SMF : zfs-auto-snapshot [start | stop]"
echo "Usage from cron: zfs-auto-snapshot svc:/system/filesystem/zfs/auto-snapshot:instance"
result=$SMF_EXIT_ERR_FATAL
;;
esac
;;
esac

View File

@ -26,7 +26,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.6'>
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,mybackup' enabled='false' >

View File

@ -0,0 +1,63 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-archive'>
<!-- a simple instance that snapshots the space/archive filesystem every 6 hours -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-archive' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/archive"
override="true"/>
<propval name="interval" type="astring" value="hours"
override="true"/>
<propval name="period" type="astring" value="6"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="2"
override="true"/>
<propval name="snapshot-children" type="boolean" value="false"
override="true"/>
<propval name="backup" type="astring" value="none"
override="true"/>
<propval name="backup-save-cmd" type="astring" value=""
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value=""
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,65 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-timf,backup'>
<!-- A service instance that backs up space/timf every month, keeping
122 months of snapshots. It saves each snapshot stream into the /extra
filesystem, naming the files according to the snapshot name -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,backup' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/timf"
override="true"/>
<propval name="interval" type="astring" value="months"
override="true"/>
<propval name="period" type="astring" value="1"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="122"
override="true"/>
<propval name="snapshot-children" type="boolean" value="true"
override="true"/>
<propval name="backup" type="astring" value="full"
override="true"/>
<propval name="backup-save-cmd" type="astring" value="eval cat > /extra/`echo $LAST_SNAP | sed -e 's#/#-#g'`"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="backup"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-timf,daily'>
<!-- A service instance to take daily snapshots of space/timf. It keeps 7 days
worth of snapshots into the past, before deleting them -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,daily' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/timf"
override="true"/>
<propval name="interval" type="astring" value="days"
override="true"/>
<propval name="period" type="astring" value="1"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="7"
override="true"/>
<propval name="snapshot-children" type="boolean" value="true"
override="true"/>
<propval name="backup" type="astring" value="none"
override="true"/>
<propval name="backup-save-cmd" type="astring" value="eval cat > /extra/`echo $LAST_SNAP | sed -e 's#/#-#g'`"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="daily"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-timf,frequent'>
<!-- A service instance that takes snapshots every 10 minutes, keeping 60 snapshots
into the past. All child filesystems of space/timf are also snapshotted. -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,frequent' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/timf"
override="true"/>
<propval name="interval" type="astring" value="minutes"
override="true"/>
<propval name="period" type="astring" value="10"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="60"
override="true"/>
<propval name="snapshot-children" type="boolean" value="true"
override="true"/>
<propval name="backup" type="astring" value="none"
override="true"/>
<propval name="backup-save-cmd" type="astring" value=""
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="frequent"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-timf,monthly'>
<!-- A service instance to take monthly snapshots of space/timf. Child filesystems
are also snapshotted, and backups are taken into the /extra filesystem. -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,monthly' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/timf"
override="true"/>
<propval name="interval" type="astring" value="months"
override="true"/>
<propval name="period" type="astring" value="1"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="3"
override="true"/>
<propval name="snapshot-children" type="boolean" value="true"
override="true"/>
<propval name="backup" type="astring" value="full"
override="true"/>
<propval name="backup-save-cmd" type="astring" value="eval cat > /extra/`echo $LAST_SNAP | sed -e 's#/#-#g'`"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="monthly"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='tank-root_filesystem'>
<!-- A service instance that takes snapshots every 5 days of my mountroot
filesystem -->
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='tank-root_filesystem' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="tank/root_filesystem"
override="true"/>
<propval name="interval" type="astring" value="days"
override="true"/>
<propval name="period" type="astring" value="5"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="3"
override="true"/>
<propval name="snapshot-children" type="boolean" value="false"
override="true"/>
<propval name="backup" type="astring" value="none"
override="true"/>
<propval name="backup-save-cmd" type="astring" value=""
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value=""
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -310,7 +310,7 @@ cat > auto-snapshot-instance.xml <<EOF
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.6'>
version='0.7'>
<create_default_instance enabled='false' />
<instance name='${ESCAPED_NAME}' enabled='false' >

View File

@ -32,7 +32,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.6'>
version='0.7'>
<!-- no point in being able to take snapshots if we don't have a fs -->
<dependency