From: hackbard Date: Sat, 27 Aug 2005 15:54:47 +0000 (+0000) Subject: initial checkin of fai_backup.sh X-Git-Url: https://hackdaworld.org/gitweb/?p=scripts%2Fscripts.git;a=commitdiff_plain;h=83800cf60ee276c60104b99be50a927d021751c7 initial checkin of fai_backup.sh --- diff --git a/README b/README index aef6cd1..f930e58 100644 --- a/README +++ b/README @@ -1,5 +1,8 @@ # some scripts +- fai_backup.sh + backup config files in fai manner + - backup.sh simple script making backups of important files and data. diff --git a/fai_backup.sh b/fai_backup.sh new file mode 100755 index 0000000..314f053 --- /dev/null +++ b/fai_backup.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# subroutines: +configcp() { + file=$1 + mkdir -p $configdir/$file + cp -v $file $configdir/$file/$myip +} +backupcp() { + cat=$1 + object=$2 + if [ "$cat" = "dir" ] ; then + rsync -av $object/ $backupdir/$object + elif [ "$cat" = "file" ] ; then + dir=`dirname $object` + rsync -av $object $backupdir/$dirname/ + else + echo "warning: dont know how to handle $cat" + fi +} + +# variables +cserver="hermes" # configs which may be restored by fai +rcdir="/mnt/extra/hdw-linux/fai/files" +configdir="/mnt/tmp1" + +bserver="hermes" # data not usable for fai +rbdir="/mnt/extra/backup" +backupdir="/mnt/tmp2" + +# initializing custom variables +host=`hostname` +myip="`host $host | awk '{ print $4 }'`" +res=$? +if [ "$res" != "0" ] ; then + echo "unable to determine the hosts ip address" + exit 1 +fi +answer=n +echo "warning: the correct ip address is essential" +echo "please make sure it is the correct one" +echo "is the ip address correct? -> $myip [y/n]" +read answer +[ "$answer" != "y" ] && exit 1 + +# mount backup and config space +if [ -d $configdir -a -d $backupdir ] ; then + mount $cserver:$rcdir $configdir + res=$? + if [ "$res" != "0" ] ; then + echo "unable to mount configdir" + exit 1 + fi + mount $bserver:$rbdir $backupdir + if [ "$res" != "0" ] ; then + echo "unable to mount backupdir" + exit 1 + fi + res=$? + [ "$res" = "0" ] && b_mounted=1 +else + echo "$configdir or $backupdir (or both) doesn't exist" + exit 1 +fi + +# config: +for configfile in /usr/src/kernel/*config; do + configcp $configfile +done +for onefile in profile network kernel wireless; do + configfile="/etc/conf/$onefile" + [ -f $configfile ] && configcp $configfile +done +for configfile in /etc/cron.d/* /var/spool/cron/crontabs/*; do + [ -f $configfile ] && configcp $configfile +done +for configfile in /etc/udev/rules.d/udev.rules /etc/X11/xorg.conf* \ + /etc/opt/apache2/{httpd,ssl}.conf /etc/cups/cupsd.conf \ + /etc/ppp/{pppoe.conf,ip-up,ip-down,pap-secrets} ; do + [ -f $configfile ] && configcp $configfile +done +for i in dhcpd.conf fstab hosts host.conf hosts.allow hosts.deny lilo.conf \ + profile sendmail.cf resolv.conf exports fb.modes inetd.conf \ + xinetd.conf mp3user mp3db.conf modules.conf named.conf \ + modprobe.devfs modprobe.conf crontab ethers HOSTNAME; do + [ -f /etc/$i ] && configcp /etc/$i +done +for configfile in /var/named/*; do + [ -f $configfile ] && configcp $configfile +done +for configfile in /home/*/{xinitrc,.Xdefaults,.XHkeys,.directfbrc,.bashrc} \ + /home/*/{.signature,sp12/*,.licq,.irssi,.ssh/*} ; do + [ -f $configfile ] && configcp $configfile +done +for configfile in `find /tftpboot -type f`; do + configcp $configfile +done + +umount $configdir +umount $backupdir + +echo "done ..."