#
# 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
# 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 2012 Nexenta Sysytems, Inc. All rights reserved.
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
LC_ALL=C
{
echo "usage: $0 [-r rootdir]" >&2
echo "
See http://illumos.org/msg/SMF-8000-MY for more information on the use of
this script."
exit 2;
}
myroot=/
while getopts r: opt; do
if [ ! -d $myroot ]; then
echo "$myroot: not a directory" >&2
exit 1
fi
# validate directory and make sure it ends in '/'.
//*) echo "$myroot: must begin with a single /" >&2
usage;;
/) echo "$myroot: alternate root cannot be /" >&2
usage;;
/*/) ;; # ends with /
*) echo "$myroot: must be a full path" >&2
usage;;
esac;;
?) usage;;
esac
done
# getopts(1) didn't slurp up everything.
fi
#
# Note that the below test is carefully constructed to fail *open*; if
# anything goes wrong, it will drive onward.
#
echo "$0: may only be invoked by root" >&2
exit 2
fi
echo >&2 "
See http://illumos.org/msg/SMF-8000-MY for more information on the use of
this script to restore backup copies of the smf(5) repository.
If there are any problems which need human intervention, this script will
give instructions and then exit back to your shell."
if [ "$myroot" = "/" ]; then
system="system"
echo >&2 "
Note that upon full completion of this script, the $system will be rebooted
using reboot(1M), which will interrupt any active services.
"
fi
# check that the filesystem is as expected
cd "$myroot" || exit 1
cd "$myroot$repositorydir" || exit 1
nouser=false
rootro=false
# check to make sure /usr is mounted
nouser=true
fi
if [ ! -w "$myroot" ]; then
rootro=true
fi
echo "The / filesystem is mounted read-only, and the /usr" >&2
echo "filesystem has not yet been mounted." >&2
elif [ "$nouser" = true ]; then
echo "The /usr filesystem has not yet been mounted." >&2
else
echo "The / filesystem is mounted read-only." >&2
fi
echo >&2 "
This must be rectified before $0 can continue.
If / or /usr are on SVM (md(7d)) partitions, first run
To properly mount / and /usr, run:
then
After those have completed successfully, re-run:
$0 $*
to continue.
"
exit 1
fi
# at this point, we know / is mounted read-write, and /usr is mounted.
/bin/ls -1rt $repository-*-[0-9]*[0-9] | \
`"
if [ -z "$oldreps" ]; then
cat >&2 <<EOF
There are no available backups of $myroot$repositorydir/$repository.db.
The only available repository is "-seed-". Note that restoring the seed
will lose all customizations, including those made by the system during
the installation and/or upgrade process.
EOF
prompt="Enter -seed- to restore from the seed, or -quit- to exit: \c"
else
cat >&2 <<EOF
The following backups of $myroot$repositorydir/$repository.db exist, from
oldest to newest:
$oldreps
The backups are named based on their type and the time what they were taken.
Backups beginning with "boot" are made before the first change is made to
the repository after system boot. Backups beginning with "manifest_import"
are made after svc:/system/manifest-import:default finishes its processing.
The time of backup is given in YYYYMMDD_HHMMSS format.
Please enter either a specific backup repository from the above list to
restore it, or one of the following choices:
CHOICE ACTION
---------------- ----------------------------------------------
boot restore the most recent post-boot backup
manifest_import restore the most recent manifest_import backup
-seed- restore the initial starting repository (All
customizations will be lost, including those
made by the install/upgrade process.)
-quit- cancel script and quit
EOF
prompt="Enter response [boot]: \c"
default="boot"
fi
cont=false
while [ $cont = false ]; do
echo "$prompt"
read x || exit 1
[ -z "$x" ] && x="$default"
case "$x" in
-seed-)
else
fi;;
-quit-)
echo "Exiting."
exit 0;;
/*)
file="$x";;
*/*)
?*)
file="$myroot$repositorydir/repository-$x";;
*) file= ;;
esac
if [ -f $file ]; then
if [ -r $file ]; then
if [ -n "$checkresults" ]; then
echo "$file: integrity check failed:" >&2
echo "$checkresults" >&2
echo
else
cont=true
fi
else
echo "$file: not readable"
fi
elif [ -n "$file" ]; then
echo "$file: not found"
fi
done
if [ "$myroot" = / ]; then
svc.startd(1M) and svc.configd(1M) will be quiesced, if running."
fi
if [ -r $repo ]; then
-- renamed --> $new"
fi
if [ -r $errors ]; then
-- copied --> ${new}_errors"
fi
cat >&2 <<EOF
After confirmation, the following steps will be taken:
$steps
$file
-- copied --> $repo
EOF
if [ "$myroot" = / ]; then
echo "and the system will be rebooted with reboot(1M)."
fi
echo
cont=false
while [ $cont = false ]; do
read x || x=n
case "$x" in
cont=true;;
echo; echo "Exiting..."
exit 0;
esac;
done
umask 077 # we want files to be root-readable only.
if [ "$myroot" = / ]; then
echo
echo "Quiescing svc.startd(1M) and svc.configd(1M): \c"
if [ -n "$startd" ]; then
fi
echo "done."
fi
if [ -r "$repo" ]; then
echo "$repo"
echo " -- renamed --> $new"
:
else
echo "Failed. $startd_msg"
exit 1;
fi
fi
if [ -r $errors ]; then
echo "$errors"
echo " -- copied --> ${new}_errors"
:
else
echo "Failed. $startd_msg"
exit 1;
fi
fi
echo "$file"
echo " -- copied --> $repo"
:
else
echo "Failed. $startd_msg"
exit 1;
fi
echo
echo "The backup repository has been successfully restored."
echo
if [ "$myroot" = / ]; then
echo "Rebooting in 5 seconds."
sleep 5
fi