From 8ddb9750581f15aae0015a4152ca1515b1d1b56a Mon Sep 17 00:00:00 2001 From: Tim Foster Date: Mon, 22 Sep 2008 13:37:37 +0100 Subject: [PATCH] Remove bundled GUI and fix up pkginfo files Remove zfssnap user home directory, and fix logging accordingly --- Changelog | 2 +- src/lib/svc/method/zfs-auto-snapshot | 25 +- src/pkginfo.s | 8 +- src/postinstall | 6 +- src/prototype | 6 - src/usr/bin/zfs-auto-snapshot-admin.sh | 487 ------------------ .../applications/automatic-snapshot.desktop | 13 - 7 files changed, 14 insertions(+), 533 deletions(-) delete mode 100755 src/usr/bin/zfs-auto-snapshot-admin.sh delete mode 100644 src/usr/share/applications/automatic-snapshot.desktop diff --git a/Changelog b/Changelog index 7235c9e..f4f7a1e 100644 --- a/Changelog +++ b/Changelog @@ -3,7 +3,7 @@ * Add RBAC support - the service now runs under a zfssnap role - service start/stop logs stay under /var/svc/log - - other logs saved to /export/home/zfssnap (and syslog) + - other log messages sent to syslog * Add a 'zfs/interval' property value 'none' which doesn't use cron * Add a cache of svcprops to the method script * Add a com.sun:auto-snapshot user property used by all instances, diff --git a/src/lib/svc/method/zfs-auto-snapshot b/src/lib/svc/method/zfs-auto-snapshot index d1af5bd..4f330df 100755 --- a/src/lib/svc/method/zfs-auto-snapshot +++ b/src/lib/svc/method/zfs-auto-snapshot @@ -64,14 +64,9 @@ PREFIX="zfs-auto-snap" # clients can get confused by colons. Who knew? 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 defined -# by the schedule_snapshots take_snapshots and unschedule_snapshots -# methods. Note that for take_snapshot LOG gets set to -# a file in the zfssnap role's home directory, as we don't own -# the SMF log. Start/stop logging goes to retarter/logfile, -# everything else goes in the zfssnap role's log. +# A string we use to determine whether to echo log messages +# to stdout (and get picked up by SMF) or remain silent +# and use logger(1) to log to syslog instead. LOG="" @@ -600,24 +595,21 @@ function check_failure { # integer exit status, error message to display, be fat # A function we use to emit output. Right now, this goes to syslog via logger(1) -# as well as being appended to a log file specified by $LOG. If this logfile -# variable doesn't exist, we simply echo the message to stdout, which will -# make it's way to the final log destination via SMF, since we'll always have -# $LOG defined when being called from cron otherwise. +# as well as being echoed to stdout which will result in it being picked up by +# SMF. function print_log { # message to display logger -t zfs-auto-snap -p daemon.notice $* if [ -z "$LOG" ] ; then echo $* - else - echo $(date) $* >> $LOG fi } # Another function to emit output, this time checking to see if the # user has set the service into verbose mode, otherwise, we print nothing +# This goes to stdout, and will get collected by either SMF or cron function print_note { # mesage to display if [ "$VERBOSE" == "true" ] ; then - print_log $* + echo $(date "+%b %d %T") $* fi } @@ -945,8 +937,7 @@ case "$1" in case $SMF_FMRI in svc:/*) zfs_smf_props $SMF_FMRI - LOG_BASE=$(basename $logfile) - export LOG="$HOME/$LOG_BASE" + export LOG="false" take_snapshot $SMF_FMRI if [ $? -eq 0 ] ; then diff --git a/src/pkginfo.s b/src/pkginfo.s index ee33d19..87800ce 100644 --- a/src/pkginfo.s +++ b/src/pkginfo.s @@ -1,5 +1,5 @@ -LC_MESSAGES=en_US.UTF-8 -LANG=en_US.UTF-8 +LC_MESSAGES=C +LANG=C TZ=Eire PATH=/sbin:/usr/sbin:/usr/bin:/usr/sadm/install/bin OAMBASE=/usr/sadm/sysadm @@ -16,9 +16,9 @@ PSTAMP=~PSTAMP~ VENDOR=Sun Microsystems, Inc. HOTLINE=Please contact your local service provider CLASSES=none manifest -EMAIL=tim.foster@sun.com +EMAIL=zfs-auto-snapshot@opensolaris.org SUNW_PKGVERS=1.0 SUNW_PKG_ALLZONES=false SUNW_PKG_HOLLOW=false PKG_NONABI_SYMLINKS=true -PKGINST=TIMFauto-snapshot +PKGINST=SUNWzfs-auto-snapshot diff --git a/src/postinstall b/src/postinstall index f4e32e7..bd24bf2 100755 --- a/src/postinstall +++ b/src/postinstall @@ -62,16 +62,12 @@ fi # add the zfssnap role - probably only works on a local system :-( user_exists zfssnap if [ $? -ne 0 ] ; then - /usr/sbin/roleadd -d /export/home/zfssnap -c "ZFS Automatic Snapshots role" \ + /usr/sbin/roleadd -d / -u 51 -c "ZFS Automatic Snapshots role" \ -P "ZFS File System Management" \ -A solaris.smf.manage.zfs-auto-snapshot -m zfssnap check_error $? "Unable to create zfssnap role!" /usr/bin/passwd -r files -N zfssnap check_error $? "Unable to make zfssnap a no-password account" - - # make sure their path has /usr/sbin in it - echo "PATH=/usr/sbin:\${PATH}" >> /export/home/zfssnap/.profile - echo "export PATH" >> /export/home/zfssnap/.profile else echo "zfssnap role already exists." fi diff --git a/src/prototype b/src/prototype index f5efa5e..795460d 100644 --- a/src/prototype +++ b/src/prototype @@ -19,9 +19,3 @@ f manifest var/svc/manifest/system/filesystem/auto-snapshot-frequent.xml 0644 ro f manifest var/svc/manifest/system/filesystem/auto-snapshot-daily.xml 0644 root sys f manifest var/svc/manifest/system/filesystem/auto-snapshot-hourly.xml 0644 root sys f manifest 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 bin -f none usr/bin/zfs-auto-snapshot-admin.sh 0755 root sys diff --git a/src/usr/bin/zfs-auto-snapshot-admin.sh b/src/usr/bin/zfs-auto-snapshot-admin.sh deleted file mode 100755 index d44654c..0000000 --- a/src/usr/bin/zfs-auto-snapshot-admin.sh +++ /dev/null @@ -1,487 +0,0 @@ -#!/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. -# - -# -# 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 -# if we need to. (zenity that ships in s10u2 is based on GNOME 2.6 and doesn't -# have the same functionality as the 2.14-based zenity) -# - -MAIN_TITLE="Take regular ZFS snapshots" - -function get_interval_26 { - # Get an interval for taking snapshots - # zenity 2.6 doesn't support the --text option to --list - TITLE="${MAIN_TITLE}: Choose a time period for taking snapshots." - INTERVAL=$(zenity --list --title="${TITLE}" \ - --radiolist --column="select" \ - --column="interval" x "minutes" x "hours" x "days" x "months") - if [ $? -eq 1 ] - then - exit 1; - fi - case $INTERVAL in - 'minutes') - MAX_VAL=60 - ;; - 'hours') - MAX_VAL=24 - ;; - 'days') - MAX_VAL=31 - ;; - 'months') - MAX_VAL=12 - ;; - esac - -} - - -function get_interval { - # get an interval to take snapshots at - TITLE="${MAIN_TITLE}: Time period" - TEXT="Choose a time period for taking snapshots" - INTERVAL=$(zenity --list --title="${TITLE}" --text="${TEXT}" \ - --radiolist --column="select" \ - --column="interval" x "minutes" x "hours" x "days" x "months") - if [ $? -eq 1 ] - then - exit 1; - fi - case $INTERVAL in - 'minutes') - MAX_VAL=60 - ;; - 'hours') - MAX_VAL=24 - ;; - 'days') - MAX_VAL=31 - ;; - 'months') - MAX_VAL=12 - ;; - esac - -} - -function get_period_26 { - # work out the period we want between snapshots - # zenity 2.6 doesn't support the --scale option, use a text entry instead. - TITLE="${MAIN_TITLE}: Interval" - TEXT="Enter how often you want to take snapshots (eg. every 10 ${INTERVAL})" - PERIOD=$(zenity --entry --title="${TITLE}" --text="${TEXT}" \ - --entry-text=10) - if [ $? -eq 1 ] - then - exit 1; - fi - -} - -function get_period { - # work out the period we want between snapshots - TITLE="${MAIN_TITLE}: Interval" - TEXT="Choose how often you want to take snapshots (eg. every 10 ${INTERVAL})" - PERIOD=$(zenity --scale --title="${TITLE}" --text="${TEXT}" \ - --min-value=1 --max-value=${MAX_VAL} --value=10) - if [ $? -eq 1 ] - then - exit 1; - fi -} - - -function get_maxsnap_26 { - # choose a number of snapshots to save - # zenity 2.6 doesn't support the --scale option, use a text entry instead - TITLE="${MAIN_TITLE}: Number to save" - TEXT="Choose a maximum number of snapshots to keep, Cancel disables the limit\n\ - \n\ - (Note: once you hit this number of snapshots, the oldest will be\n\ - automatically deleted to make room)" - KEEP_SNAP=$(zenity --entry --title="${TITLE}" \ - --text="${TEXT}" --entry-text="all") - - if [ $? -eq 1 ] - then - KEEP_SNAP="all" - fi -} - - -function get_maxsnap { - # choose a number of snapshots to save - TITLE="${MAIN_TITLE}: Number to save" - TEXT="Choose a maximum number of snapshots to keep, Cancel disables the limit\n\ - \n\ - (Note: once you hit this number of snapshots, the oldest will be\n\ - automatically deleted to make room)" - KEEP_SNAP=$(zenity --scale --title="${TITLE}" \ - --text="${TEXT}" --value=1 --min-value=0 --max-value=100) - - if [ $? -eq 1 ] - then - KEEP_SNAP="all" - fi -} - -function get_snap_children { - # decide if we want to snapshot children of this filesystem - TITLE="${MAIN_TITLE}: Snapshot recursively" - TEXT="Do you want to automatically snapshot all children of this filesystem ?" - - SNAP_CHILDREN=true - $(zenity --question --text="$TEXT") - if [ $? -eq 1 ] - then - SNAP_CHILDREN=false - fi -} - - -function get_backup { - # decide if we want to do backup of this filesystem - TITLE="${MAIN_TITLE}: Remote backups" - TEXT="Choose a type of backup to perform for this filesystem:" - - BACKUP=$(zenity --list --title="${TITLE}" --text="${TEXT}" \ - --radiolist --column="select" \ - --column="type" x "full" x "incremental" x "none") - - if [ $? -eq 1 ] - then - exit 1; - fi - - case $BACKUP in - 'incremental' | 'full') - get_backup_command - ;; - *) - BACKUP="none" - ;; - esac - -} - -function get_backup_command { - # ask the user which backup command they want to use. - TITLE="${MAIN_TITLE}: Backup command" - TEXT="Enter a command you wish to run on the backup stream.\ - eg. eval cat > /net/hostname/backup.\$\$" - - BACKUP_COMMAND=$(zenity --entry --title="${TITLE}" --text="${TEXT}" \ - --entry-text="ssh timf@hostname \ -/usr/bin/pfexec /usr/sbin/zfs receive tank/backup") - if [ $? -eq 1 ] - then - exit 1; - fi - -} - - -function get_label { - # ask the user if they want to attach a label to this instance - TITLE="${MAIN_TITLE}: Label" - TEXT="Choose a label you may use to distinguish this snapshot schedule\ - from others (Alphanumeric chars only. Cancel to leave blank.)" - - LABEL=$(zenity --entry --title="${TITLE}" --text="${TEXT}" \ - --entry-text="") - if [ $? -eq 1 ] - then - LABEL="" - fi -} - -function show_summary { - # let's give the user a summary of what we've done: - - TITLE="${MAIN_TITLE}: Summary" - TEXT="The following snapshot schedule will be created :\n\n\ - Filesystem = ${FILESYS}\n\ - Interval = ${INTERVAL}\n\ - Period = ${PERIOD}\n\ - Keep snapshots = ${KEEP_SNAP}\n\ - Snapshot Children = ${SNAP_CHILDREN}\n\ - Backup = ${BACKUP}\n\ - Backup command = ${BACKUP_COMMAND}\n\ - Label = ${LABEL}\n\ - \n\ - Do you want to write this auto-snapshot manifest now ?" - - zenity --question --title="${TITLE}" --text="${TEXT}" - if [ $? -eq 1 ] - then - exit 1; - fi - -} - - -# -# 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 [ 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 -if [ $? -ne 0 ] -then - echo "Unable to see filesystem $1. Exiting now." - exit 1; -fi - - -VERSION=$(zenity --version) -if [ "$VERSION" == "2.6.0" ] -then - get_interval_26 - get_period_26 - get_maxsnap_26 - get_snap_children - get_backup - get_label - show_summary - -else - # using a more up to date zenity - get_interval - get_period - get_maxsnap - get_snap_children - get_backup - get_label - show_summary -fi - -# this is what works out the instance name: we can't have . or / -# characters in instance names, so we escape them appropriately -# eg. the auto snapshots for the ZFS filesystem tank/tims-fs are -# taken by the SMF instance -# svc:/system/filesystem/zfs/auto-snapshot:tank-tims--fs -ESCAPED_NAME=$(echo $1 | sed -e 's#-#--#g' | sed -e 's#/#-#g' \ - | sed -e 's#\.#-#g') -if [ ! -z "${LABEL}" ] -then - ESCAPED_NAME="${ESCAPED_NAME},${LABEL}" -fi -# Now we can build an SMF manifest to perform these actions... - -cat > auto-snapshot-instance.xml < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EOF - -echo "Thanks, now assuming the default SMF manifest has already been imported," -echo "you can now import the manifest for this instance, using the command :" -echo "" -echo " # svccfg import auto-snapshot-instance.xml" -echo "" -echo "then issue the command :" -echo " # svcadm enable \ -svc:/system/filesystem/zfs/auto-snapshot:$ESCAPED_NAME" -echo "" -echo "You can see what work will be done by checking your crontab." diff --git a/src/usr/share/applications/automatic-snapshot.desktop b/src/usr/share/applications/automatic-snapshot.desktop deleted file mode 100644 index 964b348..0000000 --- a/src/usr/share/applications/automatic-snapshot.desktop +++ /dev/null @@ -1,13 +0,0 @@ -[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