Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
restore232 linesDownload Raw Back to bin
1#! /bin/sh2# Restore backups.3 4# Copyright 2004-2023 Free Software Foundation, Inc.5 6# This file is part of GNU tar.7 8# GNU tar is free software; you can redistribute it and/or modify9# it under the terms of the GNU General Public License as published by10# the Free Software Foundation; either version 3 of the License, or11# (at your option) any later version.12 13# GNU tar is distributed in the hope that it will be useful,14# but WITHOUT ANY WARRANTY; without even the implied warranty of15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the16# GNU General Public License for more details.17 18# You should have received a copy of the GNU General Public License19# along with this program.  If not, see <http://www.gnu.org/licenses/>.20 21# Load library routines22SYSCONFDIR=${SYSCONFDIR-/usr/etc}23. ${LIBDIR-/usr/lib/tar}/backup.sh24 25usage() {26    	cat - <<EOF27usage: $PROGNAME [OPTIONS] [PATTERN [PATTERN...]]28Options are:29 30   -a, --all               Restore all filesystems.31   -l, --level=LEVEL       Start restoring from the given backup LEVEL32                           (default $DUMP_LEVEL).33   -v, --verbose[=LEVEL]   Set verbosity level. Default 100.34 35Informational options:36   -h, --help              Display this help message.37   -V, --version           Display program version.38 39Send bug reports to bug-tar@gnu.org.40EOF41}42 43unset PATTERN44DUMP_LEVEL=045CMDLINE="$0 $@"46 47for opt48do49  if [ -z "$prev" ]; then50      option=$opt51      optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`52  else53      option="${prev}=$opt"54      prev=""55      optarg=$opt56  fi57  case $option in58  -a|--a|--al|--all)59	 RESTORE_ALL=160	 ;;61  --l=*|--le=*|--lev=*|--leve=*|--level=*)62         DUMP_LEVEL=$optarg63	 ;;64  -l?*)  DUMP_LEVEL=`expr $option : '-l\(.*\)'`;;65  -l|--l|--le|--lev|--leve|--level)66	 prev=--level67	 ;;68  --verb=*|--verbo=*|--verbos=*|--verbose=*)69         VERBOSE=$optarg70	 ;;71  -v|--verb|--verbo|--verbos|--verbose)72         VERBOSE=10073	 ;;74  -v*)   VERBOSE=`expr $option : '-v\(.*\)'`;;75  -V|--v|--ve|--ver|--vers|--versi|--versio|--version)76    	 echo "restore (GNU tar) 1.35"77	 license78	 exit;;79  -h|--h|--he|--hel|--help)80	 usage81	 exit;;82  -*) bailout "Unknown option $opt. Try $PROGNAME --help for more info.";;83  *)  if [ -z "$PATTERN" ]; then84         PATTERN=$opt85      else86         PATTERN="$PATTERN|$opt"87      fi88      ;;89  esac90done91 92if [ -z "$RESTORE_ALL" ]; then93	if [ -z "$PATTERN" ]; then94		usage95		exit;96	fi97fi98 99init_restore100cat > $LOGFILE <<EOF101This file contains any messages produced by $PROGNAME.102 103It was created by GNU $PROGNAME, from  @PACKAGE@ (1.35).104Invocation command line was105 106  \$ $CMDLINE107 108EOF109 110restore_fs()111{112    fs="`echo \"${1}\" | sed -e 's/^.*://'`"113    fs=`root_fs $fs`114    fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"115    remotehost="`expr \"${1}\" : '\([^/][^/]*\):.*'`"116    if [ -z "$remotehost" ]; then117	remotehost=$localhost118    fi119    message 10 "fs=$fs"120    message 10 "fsname=$fsname"121    message 10 "remotehost=$remotehost"122 123    LOGPAT="`level_log_name ${fsname} '[0-9]'`"124    PREFIX="`level_log_name ${fsname} ''`"125    message 10 LOGPAT=$LOGPAT126    message 10 PREFIX=$PREFIX127    LEVELS=`remote_run "${remotehost}" ls $LOGPAT |128      sed "s,$PREFIX,," | sort -n`129    message 10 "LEVELS=$LEVELS"130 131    echo "Starting restore of ${1} at level $DUMP_LEVEL."132    for level in $LEVELS133    do134      if [ $level -lt $DUMP_LEVEL ]; then135	  message 10 "Skipping level $level"136	  continue;137      fi138      message 10 "Restoring level $level"139 140      DATE=`get_dump_time $level`141      FILE="`level_log_name ${fsname} ${level}`"142      message 10 "FILE=$FILE"143 144      LABEL="`print_level $level` backup of ${fs} on ${remotehost} at ${DATE}"145      ${RESTORE_BEGIN-:} $level $remotehost $fs $fsname146      backup_host ${remotehost} \147                  "--listed=\"$FILE\"" \148                  "--label=\"$LABEL\"" \149		  -C $fs150      ${RESTORE_END-:} $level $remotehost $fs $fsname151    done152}153 154restore_files()155{156    LOGPAT="`level_log_name MISC '[0-9]'`"157    PREFIX="`level_log_name MISC ''`"158    message 10 LOGPAT=$LOGPAT159    message 10 PREFIX=$PREFIX160    LEVELS=`remote_run "${localhost}" ls $LOGPAT | sed "s,$PREFIX,," | sort -n`161    message 10 "LEVELS=$LEVELS"162 163    echo "Starting restore of miscellaneous files at level $DUMP_LEVEL."164    for level in $LEVELS165    do166      if [ $level -lt $DUMP_LEVEL ]; then167	  message 10 "Skipping level $level"168	  continue;169      fi170      message 10 "Restoring level $level"171 172      DATE=`get_dump_time $level`173      FILE="`level_log_name MISC ${level}`"174      message 10 "FILE=$FILE"175 176      LABEL="`print_level $level` backup of miscellaneous files at ${DATE}"177      ${RESTORE_BEGIN-:} $level $localhost MISC MISC178      backup_host ${localhost} \179                  "--listed=\"$FILE\"" \180                  "--label=\"$LABEL\"" \181		  -C ${ROOT_FS-/} $@182      ${RESTORE_END-:} $level $localhost MISC MISC183    done184}185 186# Operation Overview:187#188# 1. Determine the time of the last backup189# 2. Create list of incremental listings to process190# 3. For each filesystem:191#  3.1. Start at the requested dump level (default 0) and proceed up to192#       the last available level:193#   3.1.1 Deduce the volume label194#   3.1.2. Invoke [rsh] tar --listed=FILE --label=LABEL [opts] -xf $TAPE_FILE195# 4. End196 197(message 1 "Preparing for restore"198 199message 1 "processing backup directories"200 201for dir in ${BACKUP_DIRS}202do203    message 1 "Processing $dir"204    case $dir in205	${PATTERN-*}) restore_fs $dir;;206    esac207done208 209if [ "x${BACKUP_FILES}" != "x" ] ; then210    message 1 "processing miscellaneous files"211    if [ -z "$PATTERN" ]; then212	restore_files213    else214	RESTORE_FILES=""215	for file in ${BACKUP_FILES}216	do217	  rel_file=`expr $file : '/\(.*\)'`218	  case $file in219	      $PATTERN) if [ -z "$RESTORE_FILES" ]; then220	                   RESTORE_FILES="$rel_file"221		        else222		           RESTORE_FILES="$RESTORE_FILES $rel_file"223		        fi;;224	  esac225	done226	[ -z "$RESTORE_FILES" ] || restore_files $RESTORE_FILES227    fi228 229fi) 2>&1 | tee -a "${LOGFILE}"230 231# EOF232 
codekingpro/portable-devtools · Team Ai