#!/bin/sh # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/dobackup.sh,v 1.8 2004/07/25 09:16:41 tino Exp $ # # Just run it. It does everything for you to backup you hard drive. # # $Log: dobackup.sh,v $ # Revision 1.8 2004/07/25 09:16:41 tino # see ChangeLog: bugfixes in bin/dobackup.sh and tinolib # # Revision 1.7 2004/07/05 17:18:29 tino # working version # # Revision 1.6 2004/06/18 23:51:16 tino # see ChangeLog # # Revision 1.5 2004/06/12 11:17:46 tino # removed too frequent printing of unneccessary warnings # # Revision 1.4 2004/06/06 04:01:04 tino # little bug fixed about automated compile # # Revision 1.3 2004/05/21 03:43:26 tino # will try if it works as expected soon # # Revision 1.2 2004/05/04 17:48:40 tino # bugs fixed, no works as expected # # Revision 1.1 2004/05/04 05:11:01 tino # sc-backup.sh: backup via scylla+charybis; dobackup.sh convenience script HERE="/backup/md5backup" DIRS="dbm log md5 out tmp ign" BINS="backup.sh check.sh statistics.sh sc-move.sh ../md5backup" if [ .root != ".`id -un`" ] then echo "$0 must be called by root. SU to root and try again." >&2 exit 1 fi presskey() { echo -n "Press return to continue, ^D to abort -> " read || exit 1 echo } pressy() { echo -n "$* (y/N)? " read || exit 1 [ .y = ".$REPLY" ] || exit 1 } isme() { cmp -s "$0" "$1" } setupdir() { if isme "$HERE/dobackup.sh" then echo "You must call this from directory $HERE" >&2 exit 1 fi echo echo "Seems you are new to md5backup. Welcome!" echo "" echo "First some important warnings:" echo "THERE IS NO AUTOMATED RESTORE YET! BE WARNED!" echo "This is release early, release often code." echo "So this is no production grade backup system," echo "you are only allowed to use this at your own risk" echo "and you agree to never hold liable the author" echo "(Valentin Hilbig) in case of data loss or malfunction." echo "" echo "This script assumes, you call it from directory $HERE" presskey echo "This script you are using is a convenience script:" echo "$0" echo "If you need something more nifty, you must do it yourself." echo "" echo "The directory $HERE will grow extremely big!" echo "All files on your hard drive will be copied there," echo "and it will keep all old versions of the files, too." echo "" echo "Usually you will want to mount a backup hard drive there," echo "or you will want to mount it from NFS. The directory can be" echo "local if you want to use it for (the very experimental)" echo "sc-backup.sh networked backup based on Scylla+Charybdis." presskey echo "You can always stop the following questions by EOF or" echo "interrupting this process (usually Ctrl-C)." echo for a in "$HERE" do if [ ! -e "$a" ] then echo "directory $a does not exist." pressy "Shall I create it" mkdir -p "$a" || exit 1 fi if [ ! -d "$a" ] then echo "error: $a is no directory" exit 1 fi done need="`df -kP | awk '{ all+=$3 } END { print all }'`" have="`df -kP "$HERE" | awk '{ have=$4 } END { print have }'`" if ! [ $have -gt $need ] then echo "Warning!" echo "It does not look like you have enough free space" echo "in directory $HERE to keep all the files." echo fi if [ ! -d "$HERE/bin" ] then echo "Directory $HERE/bin does not exist." bindir="`dirname "$0"`" bindir="`cd "$bindir"; echo $PWD`" if ! isme "$bindir/dobackup.sh" then echo "Weird." echo "$bindir does not contain dobackup.sh," echo "or the script you called is not this dobackup.sh." echo "Please try to call $bindir/dobackup.sh" echo "or whatever. Puzzled." exit 1 fi echo "Directory $bindir" echo "shall be linked or copied there." pressy "Shall I make the softlink for you" ln -s "$bindir" "$HERE"/bin || exit 1 fi if ! isme "$HERE/bin/dobackup.sh" then echo "$HERE/bin/dobackup.sh is not this script here." echo "Please correct this first." echo "Perhaps cleanup (remove?) directory $HERE." echo "But be sure to not delete something valuable!" exit 1 fi if ! isme "$HERE/dobackup.sh" then echo "$HERE/dobackup.sh does not exist" pressy "Shall I create the softlink for you" ln -s bin/dobackup.sh "$HERE"/ fi echo "Directory was setup successfully." echo "Please now do following:" echo "cd $HERE" echo "./dobackup.sh" echo "" echo "Remember: $HERE must have a lot of free space!" exit 1 } setup() { echo if ! isme "$HERE/dobackup.sh" || [ "x$HERE" != "x$PWD" ] then setupdir fi if [ ! -x bin/../md5backup -a -r bin/../md5backup.c ] then echo "The main program (md5backup) is missing and must be compiled." pressy "Shall I try to compile it for you" ( cd bin && cd "`/bin/pwd`" && cd .. && make ) echo if [ ! -x bin/../md5backup ] then echo "Compile failed. Sorry." exit 1 fi fi for a in $BINS do if [ ! -x "bin/$a" ] then echo "some needed binary is missing: bin/$a" echo "Please make sure:" echo "softlink exists: ln -s /md5backup_source_dir/bin ." echo "(replace md5backup_source_dir with the path to the source)" echo "md5backup is compiled (in bin/../ just type: make)" exit 1 fi done echo "Some missing directories will now be created." echo "Please note that you can/should do following first:" echo "1) Create a softlink for the dbm directory to point to the hard drive" echo " to speed up things if $HERE is a slow disk or networked." echo "2) Create directories named ln... where ... can be a number etc." echo " This allows to track new files in out, i. e. additional net-backup," echo " you perhaps may want to use sc-backup.sh (needs scylla+charybdis)." echo " See doc/sc-backup.sh for more information." presskey for a in $DIRS do [ -d "$a" ] || mkdir "$a" || exit 1 done echo "The directory $HERE/ign/" echo "lists all files and directories to ignore for backup." echo "There are two possiblilities to enter something there:" echo "1) softlink it to an unique name (ln -s /to/ignore ign)" echo "2) write a file which lists the absolute paths of ignores line by line" echo "Usually you want to ignore frequently changing files there," echo "like logfiles or temporary files which are needed only during runtime." echo "" echo "Standard ignores will be added now. If you don't want this," echo "stop this script and restart it again." presskey for a in bin/../ign/* do [ ! -f "$a" ] && continue case "$a" in *~|*.bak) continue; esac to="ign/`basename "$a"`" [ -e "$to" ] && if [ -L "$to" ] || [ ! -f "$to" ] || ! cmp -s "$a" "$to" then echo "==========================" diff -u "$a" "$to" echo "==========================" pressy "remove existing $to" rm -f "$to" fi cp -vf "$a" "$to" || exit 1 done echo "Everything is set up for backup now. In future you will no more" echo "be prompted again. Backup will start now!" echo "" echo "Please don't forget that today no automated restore utility exists!" echo "And that this all here comes without any guarantee or warranty!" presskey } for a in $BINS do if [ ! -x "bin/$a" ] then echo "missing bin/$a" setup >&2 break fi done for a in $DIRS do if [ ! -d "$a" ] then echo "missing dir $a" setup >&2 break fi done exec bin/backup.sh "$@"