#!/bin/bash # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/backup.sh,v 1.11 2004/09/28 23:52:52 tino Exp $ # # PLEASE NOTE THAT THE CORRESPONDING RESTORE STILL IS MISSING! # # This is *my* backup script for Linux. # It backs up all files *except* /proc, /var/lib/mysql and following mounts: # # /backup # /mnt # everything below /mnt/ # # You can backup mounts by explicitely stating them on the command line, # however this only backs up what you give on the command line. # # Output is written to /backup/md5backup/ # (this is why /backup is expected to be a mount) # # If you create directories /backup/md5backup/ln* # then new output is hardlinked there, too ('=' feature of md5backup). # # Ignores can be added to directory /backup/md5backup/ign/ # either as softlinks to dir/file or files which contain the ignore list # ('-' feature of md5backup). # # -Tino # # $Log: backup.sh,v $ # Revision 1.11 2004/09/28 23:52:52 tino # iso9660 and loopback filesystems are now ignored # # Revision 1.10 2004/08/31 00:05:19 tino # improved hostname detection # # Revision 1.9 2004/07/03 12:55:03 tino # working version commit # # Revision 1.8 2004/06/18 23:51:16 tino # see ChangeLog # # Revision 1.7 2004/05/01 04:38:39 tino # sigh, forgot to take out a debug echo # # Revision 1.6 2004/05/01 04:37:36 tino # now it works as expected # # Revision 1.5 2004/05/01 02:15:01 tino # New feature: +/PATH/ # # Revision 1.4 2004/04/24 01:10:46 tino # Intermediate version, I start to implement linked file store now # # Revision 1.3 2004/01/11 20:29:29 tino # Release candidate: Added features: # Autoignore and stay in local filesystem # # Revision 1.2 2004/01/07 12:05:09 tino # Scripts improved, some spelling corrections, and CVS headers added. # md5backup.c now has a sanity check which slows down things factor 10. MD5BACKUPWORKDIR=/backup/md5backup getpath() { ( cd "`dirname "$0"`"; cd "`/bin/pwd`"; cd "$1"; /bin/pwd; ) } MD5BACKUP="`getpath ..`/md5backup" if [ ! -x "$MD5BACKUP" ] then echo "cannot locate md5backup utility: $MD5BACKUP" >&2 exit 1 fi backupper() { #echo "call: $*"; exit 1 i=0 a="" while let i=i+1 [ $i -le $# ] do eval v=\"\$$i\" a="$a \"\$$i\"" done # moved this into a file as it can become quite big # YESSSSS, I do not support linefeeds in names. # Use a ign-softlink for that with some proper name, ok? targs="$MD5BACKUPWORKDIR/tmp/targetlist.$$" > "$targs" for b in $MD5BACKUPWORKDIR/ln* do [ -d "$b" ] && echo "=$b" >> "$targs" done for b in $MD5BACKUPWORKDIR/ign/* /var/lib/mysql /proc do if [ -f "$b" -a ! -L "$b" ] then # only transport lines which start with a / # this way you can comment out things easily # Note that I do not want you to add includes, # as this has surprising results (adds instead removes) sed -n 's|^/|-/|p' "$b" >> "$targs" elif [ -r "$b" ] then echo "-$b" >> "$targs" fi done #cat "$targs" # Works with Network HOST="`hostname -f`" # Works with Hostname set [ -z "$HOST" ] && HOST="`hostname`" # Last resort [ -z "$HOST" ] && HOST="`cat /etc/hostname`" if [ -z "$HOST" ] then echo "cannot detect your hostname (Hint: vi /etc/hostname)" >&2 exit 1 fi eval \"\$MD5BACKUP\" $MD5BACKUPWORKDIR/ \"\$HOST\" \"@\$targs\" $a rm -f "$targs" } allfs() { { echo /backup awk '/^nodev/ { print $2 }' /proc/filesystems echo iso9660 } | awk 'END { while (("mount" | getline)>0) if ($3~/^[/]/ && !ign[$5] && !ign[$3] && $3!~/^\/mnt\// && $6!~/loop=/) print $3; } { ign[$1]=1; }' } if [ 0 = $# ] then backupper `allfs` else backupper "$@" fi