#!/usr/sbin/sh # # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. # PATH=/sbin:/usr/bin:/usr/sbin LC_ALL=C export PATH LC_ALL . /lib/svc/share/smf_include.sh . /lib/svc/share/fs_include.sh usage() { echo "usage: $0 [-r rootdir]" >&2 echo " See http://support.oracle.com/msg/SMF-8000-MY for more information on the use of this script." exit 2; } repositorydir=etc/svc repository=repository myroot=/ while getopts r: opt; do case "$opt" in r) myroot=$OPTARG if [ ! -d $myroot ]; then echo "$myroot: not a directory" >&2 exit 1 fi # validate directory and make sure it ends in '/'. case "$myroot" in //*) echo "$myroot: must begin with a single /" >&2 usage;; /) echo "$myroot: alternate root cannot be /" >&2 usage;; /*/) ;; # ends with / /*) myroot="$myroot/";; # add final / *) echo "$myroot: must be a full path" >&2 usage;; esac;; ?) usage;; esac done if [ $OPTIND -le $# ]; then # getopts(1) didn't slurp up everything. usage fi # # Note that the below test is carefully constructed to fail *open*; if # anything goes wrong, it will drive onward. # if [ -x /usr/bin/id ] && [ "$(id -u 2>/dev/null)" != 0 ]; then echo "$0: may only be invoked by root" >&2 exit 2 fi echo >&2 " See http://support.oracle.com/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" -eq / ]; then system="system" [ "`/usr/sbin/zonename`" != global ] && system="zone" 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 if [ ! -x /usr/bin/pgrep ]; then nouser=true fi if [ ! -w "$myroot" ]; then rootro=true fi if [ "$nouser" = true -o "$rootro" = true ]; then if [ "$nouser" = true -a "$rootro" = true ]; then 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 /lib/svc/method/svc-metainit To properly mount / and /usr, run: /lib/svc/method/fs-root then /lib/svc/method/fs-usr 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. oldreps="` /bin/ls -1rt $repository-*-[0-9]*[0-9] | \ /bin/sed -e '/[^A-Za-z0-9_,.-]/d' -e 's/^'$repository'-//' `" if [ -z "$oldreps" ]; then cat >&2 <&2 <&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 errors="$myroot"$SMF_SYSVOL_FS/db_errors repo="$myroot$repositorydir/$repository.db" new="$repo"_old_"`date +%Y''%m''%d'_'%H''%M''%S`" steps= if [ "$myroot" = / ]; then steps="$steps svc.startd(1M) and svc.configd(1M) will be quiesced, if running." fi if [ -r $repo ]; then steps="$steps $repo -- renamed --> $new" fi if [ -r $errors ]; then steps="$steps $errors -- copied --> ${new}_errors" fi if [ "$x" = "-seed-" ]; then steps="$steps rm $repo" else steps="$steps $file -- copied --> $repo " fi cat >&2 < $new" if mv $repo $new; then : else echo "Failed. $startd_msg" exit 1; fi fi if [ -r $errors ]; then echo "$errors" echo " -- copied --> ${new}_errors" if cp -p $errors ${new}_errors; then : else mv -f $new $repo echo "Failed. $startd_msg" exit 1; fi fi if [ "$x" = "-seed-" ]; then echo "removed --> $repo" if rm -f $repo; then : else echo "Failed. $startd_msg" exit 1; fi else echo "$file" echo " -- copied --> $repo" if cp $file $repo.new.$$ && mv $repo.new.$$ $repo; then : else rm -f $repo.new.$$ ${new}_errors mv -f $new $repo echo "Failed. $startd_msg" exit 1; fi fi echo echo "The backup repository has been successfully restored." echo if [ "$myroot" = / ]; then echo "Rebooting in 5 seconds." sleep 5 reboot fi