Version 0.10

This commit is contained in:
Tim Foster 2008-06-29 18:38:39 +01:00
parent a84d1e0650
commit 89cb5a25ce
24 changed files with 1007 additions and 195 deletions

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
pkg: clean
mkdir -p proto
pkgmk -f `pwd`/src/prototype -d `pwd`/proto -r `pwd`/src
clean:
rm -rf proto/*
rmdir proto

View File

@ -1,23 +1,25 @@
NAME
ZFS Automatic Snapshot SMF Service, version 0.7
ZFS Automatic Snapshot SMF Service, version 0.10
DESCRIPTION
This is a *prototype* of a simple SMF service which you can configure to
take automatic, scheduled snapshots of any given ZFS filesystem as well
as perform simple incremental or full backups of that filesystem.
This is a simple SMF service which you can configure to take automatic,
scheduled snapshots of any given ZFS filesystem as well as perform simple
incremental or full backups of that filesystem.
To use the service, the user must install the method script, import the default
instance, and then create instances for each ZFS filesystem that should be
managed by the service.
Documentation for the service instance is contained in the manifest file,
Documentation for the service is contained in the manifest file,
zfs-auto-snapshot.xml.
As of version 0.9 there is a simple GUI that allows the user to configure
which filesystems are to be included in the default canned SMF instances.
This GUI is installed in the GNOME menu under:
Administration -> Automatic Snapshots
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
GUI is documented as part of the installation instructions below.
@ -26,15 +28,42 @@ GUI is documented as part of the installation instructions below.
INSTALLATION
To install, as root, run the following commands:
To install, as root, pkgadd TIMFauto-snapshot. This package now contains
several canned SMF instances which are enabled by default. These are:
# cp zfs-auto-snapshot/lib/svc/method/zfs-auto-snapshot /lib/svc/method
# svccfg import zfs-auto-snapshot/zfs-auto-snapshot.xml
online 1:17:43 svc:/system/filesystem/zfs/auto-snapshot:hourly
online 1:17:46 svc:/system/filesystem/zfs/auto-snapshot:monthly
online 1:17:46 svc:/system/filesystem/zfs/auto-snapshot:daily
online 1:17:48 svc:/system/filesystem/zfs/auto-snapshot:frequent
online 1:17:49 svc:/system/filesystem/zfs/auto-snapshot:weekly
Once you have installed these, you need to create an instance of the service
for each set of ZFS snapshots you want to take. The properties we need are:
These instances use the special "//" fs-name to determine which filesystems
should be included in each snapshot schedule. See the description for "fs-name"
below.
zfs/fs-name The name of the filesystem
The included instances have the following properties:
frequent snapshots every 15 mins, keeping 4 snapshots
hourly snapshots every hour, keeping 24 snapshots
daily snapshots every day, keeping 31 snapshots
weekly snapshots every week, keeping 7 snapshots
monthly snapshots every month, keeping 12 snapshots
The default service instance does not need to be enabled.
Additional instances of the service can also be created, for example to group
related sets of filesystems under a single service instance.
The properties each instance needs are:
zfs/fs-name The name of the filesystem. If the special filesystem
name "//" is used, then the system snapshots all
filesystems with the zfs user property
"com.sun:auto-snapshot:<label>" set to true, so to take
frequent snapshots of tank/timf, run the following zfs
command:
# zfs set com.sun:auto-snapshot:frequent=true tank/timf
zfs/interval [ hours | days | months ]
@ -57,6 +86,16 @@ for each set of ZFS snapshots you want to take. The properties we need are:
zfs/label A label that can be used to differentiate this set of
backups from others, not required.
zfs/verbose Set to false by default, setting to true makes the
service produce more output about what it's doing.
zfs/avoidscrub Set to true by default, this determines whether
we should avoid taking snapshots on any pools that have
a scrub or resilver in progress.
More info in the bugid:
6343667 need itinerary so interrupted scrub/resilver
doesn't have to start over
An example instance manifest is included in this archive.
@ -102,5 +141,8 @@ 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
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_snapshots_0_10
The ZFS Automatic Snapshot SMF Service is released under the terms of the CDDL.

View File

@ -1,82 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
CDDL HEADER START
The contents of this file are subject to the terms of the
Common Development and Distribution License, Version 1.0 only
(the "License"). You may not use this file except in compliance
with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions
and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at usr/src/OPENSOLARIS.LICENSE.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END
-->
<service_bundle type='manifest' name='space-timf,mybackup'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
<create_default_instance enabled='false' />
<instance name='space-timf,mybackup' 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>
<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="30"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="all"
override="true"/>
<propval name="snapshot-children" type="boolean" value="false"
override="true"/>
<propval name="backup" type="astring" value="full"
override="true"/>
<propval name="backup-save-cmd" type="astring"
value="/usr/bin/ssh timf@usuki /usr/bin/pfexec /usr/sbin/zfs receive -d tank/backup"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="mybackup"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -1,13 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='space-timf,10mins'>
<service_bundle type='manifest' name='tank-timf-torrent,foo'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-timf,10mins' enabled='false' >
<instance name='tank-timf-torrent,foo' enabled='false' >
<exec_method
type='method'
@ -28,27 +28,30 @@
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="space/timf"
<propval name="fs-name" type="astring" value="tank/timf/torrent"
override="true"/>
<propval name="interval" type="astring" value="minutes"
<propval name="interval" type="astring" value="hours"
override="true"/>
<propval name="period" type="astring" value="10"
<propval name="period" type="astring" value="14"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="12"
<propval name="keep" type="astring" value="16"
override="true"/>
<propval name="snapshot-children" type="boolean" value="true"
<propval name="snapshot-children" type="boolean" value="false"
override="true"/>
<propval name="backup" type="astring" value="none"
<propval name="backup" type="astring" value="incremental"
override="true"/>
<propval name="backup-save-cmd" type="astring" value=""
<propval name="backup-save-cmd" type="astring" value="ssh timf@hostname /usr/bin/pfexec /usr/sbin/zfs receive tank/backup"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="10mins"
<propval name="label" type="astring" value="foo"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
</property_group>

2
src/copyright Normal file
View File

@ -0,0 +1,2 @@
Copyright 2008 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.

View File

@ -21,7 +21,7 @@
#
# 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.
#
@ -48,14 +48,23 @@
# service, and log an appropriate error message.
. /lib/svc/share/smf_include.sh
result=$SMF_EXIT_OK
# A prefix we use on all snapshot created by this script.
# See the definition of $SNAPNAME in the take_snapshot()
# function for more information.
PREFIX="zfs-auto-snap"
# A separator character for date strings, and to delimit
# snapshot label names. Needed because apparantly Samba
# clients can get confused by colons. Who knew?
SEP=":"
# 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
# on the properties set in the service instance.
@ -85,9 +94,12 @@ function schedule_snapshots {
# for now, we're forcing the offset to be 0 seconds.
typeset OFFSET=0
# validate the filesystem
zfs list $FILESYS 2>&1 1> /dev/null
check_failure $? "ZFS filesystem does not exist!"
if [ "$FILESYS" != "//" ]
then
# validate the filesystem
zfs list $FILESYS 2>&1 1> /dev/null
check_failure $? "ZFS filesystem does not exist!"
fi
# remove anything that's there at the moment
unschedule_snapshots $FMRI
@ -147,13 +159,36 @@ function add_cron_job { # $INTERVAL $PERIOD $OFFSET $FMRI
;;
esac
# Since we may have multiple instances all trying to start at
# the same time, we need some form of locking around crontab.
# Normally we'd be able to get SMF to manage this, by defining dependencies -
# but I'm not sure there's a way to prevent it from starting two instances
# at the same time (without requiring users to explicitly state dependencies
# and change them each time new instances are added)
# This isn't perfect (eg. if someone else if running crontab at the
# same time as us, we'll fail) but it'll do for now.
LOCK_OWNED="false"
while [ "$LOCK_OWNED" == "false" ]
do
mkdir /tmp/zfs-auto-snapshot-lock
if [ $? -eq 0 ]
then
LOCK_OWNED=true
else
sleep 1
fi
done
# adding a cron job is essentially just looking for an existing entry,
# removing it, and appending a new one. Neato.
crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" > /tmp/saved-crontab.$$
echo "${ENTRY} /lib/svc/method/zfs-auto-snapshot $FMRI" >> /tmp/saved-crontab.$$
crontab /tmp/saved-crontab.$$
check_failure $? "Unable to add cron job!"
# release our lock
rm -rf /tmp/zfs-auto-snapshot-lock
rm /tmp/saved-crontab.$$
return 0
}
@ -166,9 +201,24 @@ function unschedule_snapshots {
typeset FMRI=$1
# See notes on $LOCK_OWNED variable in function add_cron_job
LOCK_OWNED="false"
while [ "$LOCK_OWNED" == "false" ]
do
mkdir /tmp/zfs-auto-snapshot-lock
if [ $? -eq 0 ]
then
LOCK_OWNED=true
else
sleep 1
fi
done
crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot $FMRI$" > /tmp/saved-crontab.$$
crontab /tmp/saved-crontab.$$
check_failure $? "Unable to unschedule snapshots for $FMRI"
rm -rf /tmp/zfs-auto-snapshot-lock
rm /tmp/saved-crontab.$$
# finally, check our status before we return
@ -189,7 +239,7 @@ function take_snapshot {
typeset FMRI=$1
typeset DATE=$(date +%F-%H:%M:%S)
typeset DATE=$(date +%F-%H${SEP}%M${SEP}%S)
typeset FILESYS=$(svcprop -p zfs/fs-name $FMRI)
typeset KEEP=$(svcprop -p zfs/keep $FMRI)
typeset SNAP_CHILDREN=$(svcprop -p zfs/snapshot-children $FMRI)
@ -197,64 +247,119 @@ function take_snapshot {
typeset BACKUP=$(svcprop -p zfs/backup $FMRI)
typeset STATE=0
# an identifier allows us to setup multiple snapshot schedules
# per filesystem - so we append a :<id> token if the user has
# per filesystem - so we append a <sep><label> token if the user has
# requested one, which then gets used in the SNAPNAME. SMF
# returns the value '""' for the empty string to differentiate
# between an unset property, and a set-but-empty property.
# Shocking, I know.
typeset LABEL="$(svcprop -p zfs/label $FMRI)"
# the "//" filesystem is special. We use it as a keyword
# to determine whether to poll the ZFS "com.sun:auto-snapshot:${LABEL}"
# user property which specifies which datasets should be snapshotted
# and under which "label" - a set of default service instances that
# snapshot at defined periods (daily, weekly, monthly, every 15 mins)
if [ "$FILESYS" == "//" ]
then
FILESYS=$(get_snapshot_datasets $LABEL)
else
FILESYS=$FILESYS
fi
if [ "$LABEL" != "\"\"" ]
then
LABEL=":${LABEL}"
LABEL="${SEP}${LABEL}"
else
LABEL=""
fi
typeset SNAPNAME="zfs-auto-snap${LABEL}-${DATE}"
# A flag for whether we're running in verbose mode or not
VERBOSE="$(svcprop -p zfs/verbose $FMRI)"
typeset SNAPNAME="${PREFIX}${LABEL}-${DATE}"
# Determine whether we should avoid scrubbing
typeset AVOIDSCRUB=$(svcprop -p zfs/avoidscrub $FMRI)
# Ok, now say cheese! If we're taking recursive snapshots,
# walk through the children, destroying old ones if required.
if [ "${SNAP_CHILDREN}" == "true" ]
# prune out the filesystems that are on pools currently being
# scrubbed or resilvered. There's a risk that a scrub/resilver
# will be started just after this check completes, but there's
# also the risk that a running scrub will complete just after this
# check. Life's hard.
if [ "$AVOIDSCRUB" == "true" ]
then
# a cache of the pools that are known not to be scrubbing
NOSCRUBLIST=""
OS=$(uname -r)
for child in $(zfs list -r -H -o name -t filesystem,volume $FILESYS)
do
destroy_older_snapshots $child $KEEP $LABEL
if [ "${OS}" != "5.11" ]
# Create a list of filesystems scheduled for snapshots
# that are *not* on pools that are being scrubbed/resilvered
for fs in $FILESYS
do
POOL=$(echo $fs | cut -d/ -f1)
if is_scrubbing $POOL "$NOSCRUBLIST"
then
print_log "Pool containing $fs is being scrubbed/resilvered."
print_log "Not taking snapshots for $fs."
else
NOSCRUBLIST="$POOL $NOSCRUBLIST"
NOSCRUBFILESYS="$NOSCRUBFILESYS $fs"
fi
done
FILESYS="$NOSCRUBFILESYS"
fi
# walk each of the filesystems specified
for fs in $FILESYS
do
# Ok, now say cheese! If we're taking recursive snapshots,
# walk through the children, destroying old ones if required.
if [ "${SNAP_CHILDREN}" == "true" ]
then
# Solaris 10 doesn't have recursive snapshots, but we do
# them outside the loop otherwise.
zfs snapshot $child@$SNAPNAME
check_failure $? "Unable to take snapshot $child@$SNAPNAME."
# check if we have recursive snapshot capability, seeing
# a null string in this variable says we don't.
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
if [ -z "${HAS_RECURSIVE}" ]
then
print_note "Taking snapshot $child@$SNAPNAME"
zfs snapshot $child@$SNAPNAME
check_failure $? "Unable to take snapshot $child@$SNAPNAME."
fi
done
# take the recursive snapshots if we have the ability
if [ -n "${HAS_RECURSIVE}" ]
then
print_note "Taking recursive snapshot $fs@$SNAPNAME"
zfs snapshot -r $fs@$SNAPNAME
check_failure $? "Unable to take recursive snapshots $fs@$SNAPNAME."
fi
else
destroy_older_snapshots $fs $KEEP $LABEL
print_note "Taking snapshot $fs@$SNAPNAME"
zfs snapshot $fs@$SNAPNAME
check_failure $? "Unable to take snapshot $fs@$SNAPNAME."
fi
done
# take the recursive snapshots if we're on Solaris Nevada.
if [ "${OS}" == "5.11" ]
then
zfs snapshot -r $FILESYS@$SNAPNAME
check_failure $? "Unable to take recursive snapshots $FILESYS@$SNAPNAME."
fi
else
destroy_older_snapshots $FILESYS $KEEP
zfs snapshot $FILESYS@$SNAPNAME
check_failure $? "Unable to take snapshot $FILESYS@$SNAPNAME."
fi
# If the user has asked for backups, go ahead and do this.
if [ "${BACKUP}" != "none" ]
then
take_backup $FILESYS $BACKUP "$LABEL" $FMRI
check_failure $? "Unable to backup filesystem $FILESYS using \
$BACKUP backup strategy."
fi
# If the user has asked for backups, go ahead and do this.
if [ "${BACKUP}" != "none" ]
then
take_backup $fs $BACKUP "$LABEL" $FMRI
check_failure $? "Unable to backup filesystem $fs using \
$BACKUP backup strategy."
fi
done
# finally, check our status before we return
STATE=$(svcprop -p restarter/state $FMRI)
if [ "${STATE}" == "maintenance" ]
@ -269,7 +374,7 @@ function take_snapshot {
# Given a filesystem name, and a limit of the number of snapshots we want,
# along with the identifier for this set of snapshots,
# we destroy all older snapshots of this filesystem whose names begin
# with the text "zfs-auto-snap<id>". Note that here we destroy one more snapshot
# with the text "${PREFIX}${LABEL}". Note that here we destroy one more snapshot
# than the "keep" threshold - this is because in the context of calling this
# function, we're already creating one new auto-snapshot.
#
@ -288,11 +393,12 @@ function destroy_older_snapshots {
# walk through the snapshots, newest first, destroying older ones
for snapshot in $(zfs list -r -t snapshot -H -o name $FILESYS \
| grep "$FILESYS@zfs-auto-snap${LABEL}" | sort -r)
| grep "$FILESYS@${PREFIX}${LABEL}" | sort -r)
do
if [ $COUNTER -le 0 ]
then
print_log "$snapshot being destroyed as per retention policy."
# using print_note, as this checks our $VERBOSE flag
print_note "$snapshot being destroyed as per retention policy."
zfs destroy $snapshot
check_failure $? "Unable to destroy $snapshot"
else
@ -331,6 +437,15 @@ function print_log { # message to display
logger -t zfs-auto-snap -p daemon.notice $*
}
# Another function to emit output, this time checking to see if the
# user has set the service into verbose mode, otherwise, we print nothing
function print_note { # mesage to display
if [ "$VERBOSE" == "true" ]
then
logger -t zfs-auto-snap -p daemon.notice $*
fi
}
# Given a range start, end and width of period, return a comma
# separated string of numbers within that range and conforming to
@ -344,7 +459,7 @@ function get_divisor { # start period, end period, width of period
typeset RANGE=$START
typeset JUMP=$(( $RANGE + $WIDTH ))
while [ $JUMP -lt $END ]
while [ $JUMP -le $END ]
do
RANGE="$RANGE,$JUMP"
JUMP=$(( $JUMP + $WIDTH ))
@ -417,10 +532,10 @@ function take_backup { # filesystem backup-type label fmri
"incremental")
# get the last two snapshots
LAST_SNAP=$(zfs list -H -o name -r -t snapshot $dataset \
| grep "$dataset@zfs-auto-snap${LABEL}" | tail -1)
| grep "$dataset@${PREFIX}${LABEL}" | tail -1)
PREV_SNAP=$(zfs list -H -o name -r -t snapshot $dataset \
| grep "$dataset@zfs-auto-snap${LABEL}" \
| grep "$dataset@${PREFIX}${LABEL}" \
| tail -2 | head -1)
if [ "$PREV_SNAP" == "$LAST_SNAP" ]
@ -431,7 +546,7 @@ function take_backup { # filesystem backup-type label fmri
;;
"full")
LAST_SNAP=$(zfs list -H -o name -r -t snapshot $dataset \
| grep "$dataset@zfs-auto-snap${LABEL}" | tail -1)
| grep "$dataset@${PREFIX}${LABEL}" | tail -1)
;;
*)
check_failure 1 "Unknown backup type $BACKUP"
@ -446,23 +561,68 @@ function take_backup { # filesystem backup-type label fmri
# the service as being in maintenance mode, however, backups will still
# be attempted for other datasets in our list.
case $BACKUP in
"incremental")
"incremental")
print_note "Starting incr. ZFS send of differences between $PREV_SNAP and $LAST_SNAP."
zfs send -i $PREV_SNAP $LAST_SNAP | $BACKUP_SAVE_CMD
check_failure $? "Error performing incremental backup of $dataset."
;;
"full")
print_note "Starting ZFS send of $LAST_SNAP."
zfs send $LAST_SNAP | $BACKUP_SAVE_CMD
check_failure $? "Error performing full backup of $dataset."
;;
esac
done
print_note "Backups completed for $dataset."
# Now we can release our lock
svccfg -s $FMRI setprop zfs/backup-lock = astring: "unlocked"
svcadm refresh $FMRI
}
# Get a list of filesystem we should snapshot
function get_snapshot_datasets { #LABEL
typeset LABEL=$1
typeset FS=$(zfs list -t filesystem -o name,com.sun:auto-snapshot:$LABEL \
| grep true | awk '{print $1}')
echo "$FS"
}
# Determine if a pool is currently being scrubbed or resilvered.
# Return 0 if it is scrubbing/resilvering, 1 otherwise.
# The 2nd arg is a cache of pools known to be not scrubbing during this
# invocation of the script. This does risk a scrub starting mid-way through
# the script being started and us not checking for it - but if that's just
# happened, then restarting the scrub as a result of a snapshot being taken
# won't be too expensive.
function is_scrubbing { # POOL SCRUBLIST
typeset POOL=$1
typeset NOSCRUBLIST="$2"
typeset SCRUBBING=""
# see if we can avoid running zpool status, by checking for
# the pool name in a known list of pools that were not scrubbing
# the last time we checked.
echo "$NOSCRUBLIST" | grep "$POOL " > /dev/null
if [ $? -eq 0 ]
then
return 1
fi
SCRUBBING=$(env LC_ALL=C zpool status $POOL | grep " in progress")
if [ -z "$SCRUBBING" ]
then
return 1
else
return 0
fi
}
# Here's the beginning of the main script. As we're a method script for SMF,

24
src/pkginfo Normal file
View File

@ -0,0 +1,24 @@
CLASSES=none
LC_MESSAGES=en_US.UTF-8
LANG=en_US.UTF-8
TZ=Eire
PATH=/sbin:/usr/sbin:/usr/bin:/usr/sadm/install/bin
OAMBASE=/usr/sadm/sysadm
SITENAME=Sun Microsystems
PKG=TIMFauto-snapshot
NAME=ZFS Automatic Snapshot Service
ARCH=all
BASEDIR=/
VERSION=0.10
MAXINST=1
CATEGORY=application
DESC=Takes automatic snapshots of ZFS filesystems on a periodic basis.
PSTAMP=haiiro20080122113401
VENDOR=Sun Microsystems, Inc.
HOTLINE=Please contact your local service provider
EMAIL=tim.foster@sun.com
SUNW_PKGVERS=1.0
SUNW_PKG_ALLZONES=false
SUNW_PKG_HOLLOW=false
PKG_NONABI_SYMLINKS=true
PKGINST=TIMFauto-snapshot

46
src/postinstall Executable file
View File

@ -0,0 +1,46 @@
#!/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# a postinstall script - it should import the manifests
# and enable the service
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"
FILES="auto-snapshot-daily.xml auto-snapshot-monthly.xml auto-snapshot-frequent.xml auto-snapshot-weekly.xml auto-snapshot-hourly.xml zfs-auto-snapshot.xml"
/usr/sbin/svccfg import /var/svc/manifest/system/filesystem/zfs-auto-snapshot.xml
for manifest in $FILES
do
/usr/sbin/svccfg import /var/svc/manifest/system/filesystem/$manifest
done
for fmri in $FMRIS
do
/usr/sbin/svcadm enable $fmri
done

43
src/preremove Executable file
View File

@ -0,0 +1,43 @@
#!/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# a postinstall script - it should disable the services
# and delete the instances
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"
for fmri in $FMRIS $DEFAULT
do
/usr/sbin/svcadm disable $fmri
while [ "$STATE" != "disabled" ]
do
sleep 1
STATE=`/usr/bin/svcs -H -o state $fmri`
done
/usr/sbin/svccfg delete $fmri
done

25
src/prototype Normal file
View File

@ -0,0 +1,25 @@
i pkginfo
i copyright
i postinstall
i preremove
d none var 0755 root sys
d none var/svc 0755 root sys
d none var/svc/manifest 0755 root sys
d none var/svc/manifest/system 0755 root sys
d none var/svc/manifest/system/filesystem 0755 root sys
f none var/svc/manifest/system/filesystem/zfs-auto-snapshot.xml 0644 root sys
f none var/svc/manifest/system/filesystem/auto-snapshot-monthly.xml 0644 root sys
f none var/svc/manifest/system/filesystem/auto-snapshot-frequent.xml 0644 root sys
f none var/svc/manifest/system/filesystem/auto-snapshot-daily.xml 0644 root sys
f none var/svc/manifest/system/filesystem/auto-snapshot-hourly.xml 0644 root sys
f none var/svc/manifest/system/filesystem/auto-snapshot-weekly.xml 0644 root sys
d none usr 0755 root sys
d none usr/share 0755 root sys
d none usr/share/applications 0755 root other
f none usr/share/applications/automatic-snapshot.desktop 0644 root bin
d none usr/bin 0755 root sys
f none usr/bin/zfs-auto-snapshot-admin.sh 0755 root sys
d none lib 0755 root bin
d none lib/svc 0755 root bin
d none lib/svc/method 0755 root bin
f none lib/svc/method/zfs-auto-snapshot 0755 root bin

View File

@ -7,7 +7,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-archive' enabled='false' >
@ -16,13 +16,13 @@
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -53,6 +53,10 @@
<propval name="label" type="astring" value=""
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -9,7 +9,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-timf,backup' enabled='false' >
@ -18,13 +18,13 @@
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -55,6 +55,10 @@
<propval name="label" type="astring" value="backup"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -8,7 +8,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-timf,daily' enabled='false' >
@ -17,13 +17,13 @@
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -54,6 +54,10 @@
<propval name="label" type="astring" value="daily"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -8,7 +8,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-timf,frequent' enabled='false' >
@ -17,13 +17,13 @@
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -54,6 +54,10 @@
<propval name="label" type="astring" value="frequent"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -8,7 +8,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='space-timf,monthly' enabled='false' >
@ -54,6 +54,10 @@
<propval name="label" type="astring" value="monthly"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -1,6 +1,6 @@
<?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'>
<service_bundle type='manifest' name='tank-rootfs'>
<!-- A service instance that takes snapshots every 5 days of my mountroot
filesystem -->
@ -8,22 +8,22 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='tank-root_filesystem' enabled='false' >
<instance name='tank-rootfs' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -32,7 +32,7 @@
<!-- properties for zfs automatic snapshots -->
<property_group name="zfs" type="application">
<propval name="fs-name" type="astring" value="tank/root_filesystem"
<propval name="fs-name" type="astring" value="tank/rootfs"
override="true"/>
<propval name="interval" type="astring" value="days"
override="true"/>
@ -54,6 +54,10 @@
<propval name="label" type="astring" value=""
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>

View File

@ -21,13 +21,21 @@
#
# 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.
#
#
# This script implements a simple wizard to schedule the taking of regular
# snapshots of this file system. Most of the interesting stuff is at the bottom.
# There are two modes to this script - "simple" mode, which takes no options
# and lets a user select which filesystems should have automatic snapshots taken
# using one of the built-in default schedules, or "advanced" mode, which takes
# a filesystem as an argument, and constructs an SMF manifest for the user, but
# nothing else. (it's up to the user to import the manifest and start the
# service) We don't currently let the user set the "zfs/avoidscrub" option - and
# set it to "true" by default.
#
#
# Since we'd like it to work with two different versions of zenity, we check
# the version string, and call the appropriate "_26" versions of functions
@ -84,10 +92,10 @@ function get_interval {
'hours')
MAX_VAL=24
;;
'days')
'days')
MAX_VAL=31
;;
'months')
'months')
MAX_VAL=12
;;
esac
@ -250,14 +258,109 @@ function show_summary {
}
#
# This function implements the simple mode - rather than the advanced
# mode (which builds a manifest for automatic snapshots based on user input)
# This version is much simpler, and lets a user simply select the filesystems
# they wish to have snapshots taken of, using the default monthly, daily,
# and frequent snapshot schedules which have been preconfigured.
#
function run_gui {
# ask the user to choose between configuring monthly, daily, hourly
# or frequent snapshots. This is not internationalised, sorry.
TITLE="${MAIN_TITLE}"
TEXT="Choose a snapshot schedule to configure:
(run program again to configure additional schedules)"
LABEL=$(zenity --list --title="${TITLE}" --text="${TEXT}" \
--radiolist --column="select" \
--column="Snapshot type" x "frequent" x "hourly" x "daily" x \
"weekly" x "monthly")
if [ $? -eq 1 ]
then
exit 1;
fi
FILESYSTEMS=/tmp/zfs-auto-snapshot-admin.$$
# record the current snapshot property state from all filesystems
# changing strings to either TRUE|FALSE, which conveniently are also
# the arguments that "zenity --list" uses to mark boxes as checked or not
# on entry.
zfs list -H -o com.sun:auto-snapshot:$LABEL,name -t filesystem | \
sed -e 's/^true/TRUE/g' \
-e 's/^false/FALSE/g' -e 's/^-/FALSE/g' > $FILESYSTEMS
# obtain input from the user - output is a space separated list of
# filesystems that have the checkbox selected.
ZENITY_SELECTIONS=$(
zenity --list --checklist --column="Enabled" --column="Filesystem" \
--title="$TITLE" \
--text="Select the filesystems for $LABEL automatic snapshots" \
--separator=' ' \
$(cat $FILESYSTEMS)
)
if [ $? -ne 0 ]
then
exit 1
fi
# append a space to properly delimit the last item in the list
export ZENITY_SELECTIONS="${ZENITY_SELECTIONS} "
# Walk all filesystems, checking whether the user has selected each one
# from the zenity dialog, then check to see whether the auto-snapshot
# zfs property was already set, changing it when necessary.
for fs in $(cat $FILESYSTEMS | awk '{print $2}')
do
if echo "$ZENITY_SELECTIONS" | grep "$fs " > /dev/null
then
# check to see if it's currently set to false
if cat $FILESYSTEMS | grep "^FALSE[ ]*$fs$" > /dev/null
then
# echo setting $fs to on
zfs set com.sun:auto-snapshot:$LABEL=true $fs
fi
else
# check to see if it's currently set to true
if cat $FILESYSTEMS | grep "^TRUE[ ]*$fs$" > /dev/null
then
# echo setting $fs to off
zfs set com.sun:auto-snapshot:$LABEL=false $fs
fi
fi
done
rm $FILESYSTEMS
}
## Functions out of the way, we can start the wizard properly
if [ "$#" != 1 ]
then
echo "Usage: zfs-auto-snapshot-admin.sh [zfs filesystem name]"
echo "Usage: zfs-auto-snapshot-admin.sh [ simple ] | [zfs filesystem name]"
exit 1;
fi
if [ $1 == "simple" ]
then
# run ourselves as root
if [ -z $GKSU ]
then
export GKSU=true
gksu $0 simple
exit $?
fi
run_gui
exit 0;
fi
FILESYS=$1
zfs list $FILESYS 2>&1 1> /dev/null
@ -310,7 +413,7 @@ cat > auto-snapshot-instance.xml <<EOF
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<create_default_instance enabled='false' />
<instance name='${ESCAPED_NAME}' enabled='false' >
@ -357,6 +460,12 @@ cat > auto-snapshot-instance.xml <<EOF
<propval name="label" type="astring" value="${LABEL}"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>
</instance>

View File

@ -0,0 +1,13 @@
[Desktop Entry]
Version=0.2
Encoding=UTF-8
Type=Application
Exec=/usr/bin/zfs-auto-snapshot-admin.sh simple
TryExec=/usr/bin/zfs-auto-snapshot-admin.sh
Icon=gtkam.png
X-GNOME-DocPath=
Terminal=false
Name=Automatic Snapshots
GenericName=Automatic Snapshots
Comment=Configure the system to take snapshots of ZFS filesystems at regular intervals
Categories=Application;System;Settings

View File

@ -0,0 +1,70 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='daily'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.10'>
<!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked
with the ZFS User Property com.sun:auto-snapshot:daily=true daily,
and keeps 31 of these snapshots into the past.
-->
<create_default_instance enabled='false' />
<instance name='daily' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='0' />
<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="//"
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="31"
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="not set"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="daily"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,70 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='frequent'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.10'>
<!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all 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.
-->
<create_default_instance enabled='false' />
<instance name='frequent' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='0' />
<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="//"
override="true"/>
<propval name="interval" type="astring" value="minutes"
override="true"/>
<propval name="period" type="astring" value="15"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="4"
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="not set"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="frequent"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='hourly'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.10'>
<!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It 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.
-->
<create_default_instance enabled='false' />
<instance name='hourly' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='0' />
<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="//"
override="true"/>
<propval name="interval" type="astring" value="hours"
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="24"
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="not set"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="hourly"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='monthly'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.10'>
<!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked
with the ZFS User Property com.sun:auto-snapshot:monthly=true monthly,
and keeps 12 of these snapshots into the past.
-->
<create_default_instance enabled='false' />
<instance name='monthly' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='0' />
<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="//"
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="12"
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="not set"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="monthly"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='weekly'>
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.10'>
<!-- This is one of the default instances that comes with the
ZFS Automatic Snapshot SMF Service. It snapshots all filesystems marked
with the ZFS User Property com.sun:auto-snapshot:weekly=true weekly,
and keeps 4 of these snapshots into the past.
-->
<create_default_instance enabled='false' />
<instance name='weekly' enabled='false' >
<exec_method
type='method'
name='start'
exec='/lib/svc/method/zfs-auto-snapshot start'
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/lib/svc/method/zfs-auto-snapshot stop'
timeout_seconds='0' />
<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="//"
override="true"/>
<propval name="interval" type="astring" value="days"
override="true"/>
<propval name="period" type="astring" value="7"
override="true"/>
<propval name="offset" type="astring" value="0"
override="true"/>
<propval name="keep" type="astring" value="4"
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="not set"
override="true"/>
<propval name="backup-lock" type="astring" value="unlocked"
override="true"/>
<propval name="label" type="astring" value="weekly"
override="true"/>
<propval name="verbose" type="boolean" value="false"
override="true"/>
<propval name="avoidscrub" type="boolean" value="true"
override="true"/>
</property_group>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>

View File

@ -32,7 +32,7 @@
<service
name='system/filesystem/zfs/auto-snapshot'
type='service'
version='0.7'>
version='0.10'>
<!-- no point in being able to take snapshots if we don't have a fs -->
<dependency
@ -59,7 +59,11 @@
<!-- the properties we expect that any instance will define
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
look at the com.sun:auto-snapshot:<label> ZFS user
property on datasets, set to "true" if the dataset
should have snapshots taken by this instance.
interval : minutes | hours | days | months
@ -94,6 +98,17 @@
be left unset, but it can be useful in some
situations (particularly for backups).
verbose : Set to false by default, setting to true results
in the service printing more detail in the log
about what it's doing.
avoidscrub : Set to true by default, this determines whether
we should avoid taking snapshots on any pools that have
a scrub or resilver in progress.
More info in the bugid:
6343667 need itinerary so interrupted scrub/resilver
doesn't have to start over
-->
<property_group name="zfs" type="application">
@ -108,6 +123,8 @@
<propval name="backup-lock" type="astring" value="unlocked" override="true"/>
<propval name="label" type="astring" value="" override="true"/>
<propval name="verbose" type="boolean" value="false" override="true"/>
<propval name="avoidscrub" type="boolean" value="true" override="true"/>
</property_group>
@ -118,17 +135,24 @@
<instance name='tank-timf' enabled='false' >
note: recommend an infinite timeout here - or at least a long one,
SMF tries to start all instances in parallel, however, since
we need to add entries to cron, we need to put locks around
start and stop, running these serially - if there are
sufficiently high numbers of instances, we can trip, say a 10
sec. timeout.
<exec_method
type='method'
name='start'
exec='/home/timf/zfs-auto-snapshot %m'
timeout_seconds='10' />
timeout_seconds='0' />
<exec_method
type='method'
name='stop'
exec='/home/timf/zfs-auto-snapshot %m'
timeout_seconds='10' />
timeout_seconds='0' />
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
@ -150,10 +174,19 @@
<propval name="label" type="astring" value="all" override="true"/>
<propval name="verbose" type="boolean" value="false" override="true"/>
<propval name="avoidscrub" type="boolean" value="true" override="true"/>
</property_group>
</instance>
A set of instances are provided that snapshot periodically hourly,
daily, weekly, monthly, and at 15 minute intervals, and have their
fs-name set to "//", consulting the com.sun:auto-snapshot:hourly,etc.
ZFS user properties to determine which datasets to snapshot.
-->
<stability value='Unstable' />
@ -185,6 +218,10 @@ 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
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