#!/bin/sh # Shell script to perform dumps on all important filesystems. # # Author: R.F. Smith # Time-stamp: <2012-01-14 14:39:25 rsmith> # # To the extent possible under law, Roland Smith has waived all copyright and # related or neighboring rights to dodumps. This work is published from the # Netherlands. See http://creativecommons.org/publicdomain/zero/1.0/ # Check for programs that are used in this script. PROGS="dump" for P in $PROGS; do which $P >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "$(basename $0): The program \"$P\" cannot be found." exit 1 fi done export DDATE=$(date "+%Y%m%d") # Get and check the dump level if [ $# -lt 2 ]; then echo "Usage: $(basename $0) level destdir" echo "Where 'level' should be a number in the range 0..9." echo "And 'destdir' should be the directory where the dumps will be put." echo "The $(basename $0) script must be run as root." exit 1 fi export DLVL=$1 if [ $DLVL -lt 0 -o $DLVL -gt 9 ]; then echo "Invalid dump number: ${DLVL}. Must be 0..9. Exiting." exit 1 fi # Check if the target directory exists. export DDIR=$(echo $2|sed 's/\/$//') if [ ! -d $DDIR ]; then echo "The $DDIR directory doesn't exist. Exiting." exit 1 fi # Only root can perform dumps. if [ $(id -u) -ne 0 ]; then echo "The $(basename $0) script must be run as root." exit 1 fi # Enumerate the mount points to dump. MNTS="/ /usr /var" echo "Performing level $L dump for mount points "$MNTS"." for p in $MNTS; do case $p in '/') export FSNAME=/root;; *) export FSNAME=$p;; esac OUTF=${DDIR}${FSNAME}-${DLVL}-${DDATE}.dump # Set the dump command options. DCMD="dump -${DLVL} -a -C 8 -L -u -R -h 0 -f ${OUTF} " $DCMD $p done