5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2012 Nexenta Sysytems, Inc. All rights reserved.
25 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 # Use is subject to license terms.
29 PATH
=/sbin
:/usr
/bin
:/usr
/sbin
33 .
/lib
/svc
/share
/smf_include.sh
34 .
/lib
/svc
/share
/fs_include.sh
38 echo "usage: $0 [-r rootdir]" >&2
40 See http://illumos.org/msg/SMF-8000-MY for more information on the use of
49 while getopts r
: opt
; do
52 if [ ! -d $myroot ]; then
53 echo "$myroot: not a directory" >&2
56 # validate directory and make sure it ends in '/'.
58 //*) echo "$myroot: must begin with a single /" >&2
60 /) echo "$myroot: alternate root cannot be /" >&2
64 /*) myroot
="$myroot/";; # add final /
66 *) echo "$myroot: must be a full path" >&2
73 if [ $OPTIND -le $# ]; then
74 # getopts(1) didn't slurp up everything.
79 # Note that the below test is carefully constructed to fail *open*; if
80 # anything goes wrong, it will drive onward.
82 if [ -x /usr
/bin
/id
-a -x /usr
/bin
/grep ] &&
83 /usr
/bin
/id
2>/dev
/null |
/usr
/bin
/grep -v '^[^=]*=0(' >/dev
/null
2>&1; then
84 echo "$0: may only be invoked by root" >&2
89 See http://illumos.org/msg/SMF-8000-MY for more information on the use of
90 this script to restore backup copies of the smf(5) repository.
92 If there are any problems which need human intervention, this script will
93 give instructions and then exit back to your shell."
95 if [ "$myroot" = "/" ]; then
97 [ "`/sbin/zonename`" != global
] && system
="zone"
99 Note that upon full completion of this script, the $system will be rebooted
100 using reboot(1M), which will interrupt any active services.
104 # check that the filesystem is as expected
105 cd "$myroot" ||
exit 1
106 cd "$myroot$repositorydir" ||
exit 1
111 # check to make sure /usr is mounted
112 if [ ! -x /usr
/bin
/pgrep
]; then
116 if [ ! -w "$myroot" ]; then
120 if [ "$nouser" = true
-o "$rootro" = true
]; then
121 if [ "$nouser" = true
-a "$rootro" = true
]; then
122 echo "The / filesystem is mounted read-only, and the /usr" >&2
123 echo "filesystem has not yet been mounted." >&2
124 elif [ "$nouser" = true
]; then
125 echo "The /usr filesystem has not yet been mounted." >&2
127 echo "The / filesystem is mounted read-only." >&2
131 This must be rectified before $0 can continue.
133 To properly mount / and /usr, run:
134 /lib/svc/method/fs-root
136 /lib/svc/method/fs-usr
138 After those have completed successfully, re-run:
146 # at this point, we know / is mounted read-write, and /usr is mounted.
148 /bin/ls -1rt $repository-*-[0-9]*[0-9] | \
149 /bin/sed -e '/[^A-Za-z0-9_,.-]/d' -e 's/^'$repository'-//'
152 if [ -z "$oldreps" ]; then
154 There are no available backups of $myroot$repositorydir/$repository.db.
155 The only available repository is "-seed-". Note that restoring the seed
156 will lose all customizations, including those made by the system during
157 the installation and/or upgrade process.
160 prompt
="Enter -seed- to restore from the seed, or -quit- to exit: \c"
164 The following backups of $myroot$repositorydir/$repository.db exist, from
169 The backups are named based on their type and the time what they were taken.
170 Backups beginning with "boot" are made before the first change is made to
171 the repository after system boot. Backups beginning with "manifest_import"
172 are made after svc:/system/manifest-import:default finishes its processing.
173 The time of backup is given in YYYYMMDD_HHMMSS format.
175 Please enter either a specific backup repository from the above list to
176 restore it, or one of the following choices:
179 ---------------- ----------------------------------------------
180 boot restore the most recent post-boot backup
181 manifest_import restore the most recent manifest_import backup
182 -seed- restore the initial starting repository (All
183 customizations will be lost, including those
184 made by the install/upgrade process.)
185 -quit- cancel script and quit
188 prompt
="Enter response [boot]: \c"
193 while [ $cont = false
]; do
197 [ -z "$x" ] && x
="$default"
201 if [ $myroot != / -o "`/sbin/zonename`" = global
]; then
202 file="$myroot"lib
/svc
/seed
/global.db
204 file="$myroot"lib
/svc
/seed
/nonglobal.db
214 file="$myroot$repositorydir/repository-$x";;
218 if [ -f $file ]; then
219 if [ -r $file ]; then
220 checkresults
="`echo PRAGMA integrity_check\; | \
221 /lib/svc/bin/sqlite $file >&1 | grep -v '^ok$'`"
223 if [ -n "$checkresults" ]; then
224 echo "$file: integrity check failed:" >&2
225 echo "$checkresults" >&2
231 echo "$file: not readable"
233 elif [ -n "$file" ]; then
234 echo "$file: not found"
238 errors
="$myroot"etc
/svc
/volatile
/db_errors
239 repo
="$myroot$repositorydir/$repository.db"
240 new
="$repo"_old_
"`date +%Y''%m''%d'_'%H''%M''%S`"
243 if [ "$myroot" = / ]; then
245 svc.startd(1M) and svc.configd(1M) will be quiesced, if running."
248 if [ -r $repo ]; then
253 if [ -r $errors ]; then
256 -- copied --> ${new}_errors"
261 After confirmation, the following steps will be taken:
267 if [ "$myroot" = / ]; then
268 echo "and the system will be rebooted with reboot(1M)."
273 while [ $cont = false
]; do
274 echo "Proceed [yes/no]? \c"
281 echo; echo "Exiting..."
286 umask 077 # we want files to be root-readable only.
289 if [ "$myroot" = / ]; then
291 startd
="`pgrep -z "$zone" -f svc.startd`"
294 echo "Quiescing svc.startd(1M) and svc.configd(1M): \c"
295 if [ -n "$startd" ]; then
298 "To start svc.start(1M) running, do: /usr/bin/prun $startd"
300 pkill
-z "$zone" -f svc.configd
302 sleep 1 # yes, this is hack
307 if [ -r "$repo" ]; then
309 echo " -- renamed --> $new"
310 if mv $repo $new; then
313 echo "Failed. $startd_msg"
318 if [ -r $errors ]; then
320 echo " -- copied --> ${new}_errors"
321 if cp -p $errors ${new}_errors
; then
325 echo "Failed. $startd_msg"
331 echo " -- copied --> $repo"
333 if cp $file $repo.new.$$
&& mv $repo.new.$$
$repo; then
336 rm -f $repo.new.$$
${new}_errors
338 echo "Failed. $startd_msg"
343 echo "The backup repository has been successfully restored."
346 if [ "$myroot" = / ]; then
347 echo "Rebooting in 5 seconds."