#! /bin/tcsh # # 'saveconfig' # # - writes important configuration data to floppy or USB stick # - archives important configuration files to floppy or USB stick # # Note: - a few files/commands are only accessible as root. # - most file locations should now comply to LSB. # - on SuSE systems, you also have 'siga' # # ------------------------------------------------------------------- # Creation: 2000-04-20, JHa. # Revision: 2001-01-07, JHa (sorted & multicolumn rpm output) # 2001-11-04, JHa (adjusted for new directory structure) # 2002-09-29, JHa (some changed file locations) # 2004-12-29, JHa (some changed file locations) # 2005-05-21, JHa (now /media/floppy) # 2006-12-26, JHa (updated file list; now allows other media) # ------------------------------------------------------------------- # Copyright (c) 2000-2006 Joerg Hau . # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License as published by the Free Software Foundation, provided # that the copyright notice remains intact even in future versions. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # ------------------------------------------------------------------- # Adjust this to your local setup (maybe /media/floppy, or /mnt/usb ?) # set FLOPPY = /media/sdb1 # derive archive basename from system name and actual date (not time) # set HOST = ${HOSTNAME:r} set ARCH = $HOST.`date +%Y%m%d` set LOGFILE = $FLOPPY/$ARCH.txt # Prepare a file containig the names of files and directories to be archived # set LISTFILE = "/tmp/saveconfig.$$.list" # Capture Ctrl-Break # onintr cleanup # Check if floppy is mounted. If yes, unmount it. # if ( `grep -c $FLOPPY /etc/mtab` != 0 ) then echo -n "Found a mounted medium on $FLOPPY, unmounting ... " umount $FLOPPY || exit 1 echo "done." endif echo "--- Preparing to save configuration data and files ---" echo -n "Please insert backup medium. Press any key when ready: " set dummy = $< mount $FLOPPY || echo "Error occurred during mount!" && exit 1 ######################################################################## # Part I : extract configuration data and write them into a text file ######################################################################## # list of files to print # set file = ("/etc/fstab" \ "/etc/init.d/boot.local" \ "/etc/xinetd.conf" \ "/etc/modules.conf.local" \ "/etc/lilo.conf" \ "/boot/grub/menu.lst" \ "/etc/crontab" \ "/etc/dhcpd.conf" \ "/etc/ntp.conf" \ "/etc/hosts" "/etc/hosts.equiv" \ "/etc/hosts.allow" "/etc/hosts.deny" \ "/etc/hosts.equiv" "/etc/hosts.lpd" \ "/etc/exports" "/etc/resolv.conf" \ "/etc/leafnode/config" \ "/etc/sysconfig/SuSEfirewall2" \ "/etc/printcap" "/etc/ppp/options" ) # Here we go ... # echo "==================================================================" > $LOGFILE echo "Configuration of $HOST, as of "`date`"." >> $LOGFILE echo "==================================================================" >> $LOGFILE echo "" >> $LOGFILE echo "----- Output of 'uname -a' -----" >> $LOGFILE /bin/uname -a >> $LOGFILE echo "" >> $LOGFILE echo " " >> $LOGFILE echo "----- Output of 'fdisk -l' -----" >> $LOGFILE /sbin/fdisk -l >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- Disk usage -----" >> $LOGFILE /bin/df -h >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- Networking -----" >> $LOGFILE /sbin/ifconfig >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- rpm packages installed -----" >> $LOGFILE /bin/rpm -qa | sort | pr -3 -l 1 >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- Listing of '/usr/local/bin' -----" >> $LOGFILE ls /usr/local/bin | pr -3 -l 1 >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- Listing of '/usr/local/src' -----" >> $LOGFILE ls /usr/local/src | pr -3 -l 1 >> $LOGFILE echo " " >> $LOGFILE foreach i ($file) echo " " >> $LOGFILE echo "----- "$i " -----" >> $LOGFILE # 1st grep removes comment lines (starting with #) # 2nd removes empty lines grep -v "^#" $i | grep -v ^$ >> $LOGFILE echo " " >> $LOGFILE end echo " " >> $LOGFILE echo "----- iptables-save -----" >> $LOGFILE iptables-save >> $LOGFILE echo " " >> $LOGFILE echo " " >> $LOGFILE echo "----- ip6tables-save -----" >> $LOGFILE ip6tables-save >> $LOGFILE echo " " >> $LOGFILE echo "----- NOTES -----" >> $LOGFILE echo "When re-installing the system, do not forget to ..." >> $LOGFILE echo "- put '/sbin/SuSEfirewall' as 2nd line in /etc/ppp/ip-up;">> $LOGFILE echo "- put 'su - news -c \""/usr/sbin/fetchnews &\""' in /etc/ppp/ip-up;" >> $LOGFILE echo "- optimize HDD with 'hdparm' and save them in /etc/rc.d/boot.local;" >> $LOGFILE echo "- re-install updated kppp rule sets." >> $LOGFILE echo "- install TrueType fonts." >> $LOGFILE echo "- configure efax, ntp, dhcp." >> $LOGFILE echo "-----------------" >> $LOGFILE echo " " >> $LOGFILE # I don't know if sync is useful for floppies, but it won't hurt anyway ;-) sync echo "System configuration log written to $LOGFILE." ######################################################################## # Part II: tar the configuration files to $FLOPPY ######################################################################## # create $LISTFILE ... # Make sure there is no trailing space after the # file names, otherwise tar will fail! # echo "/etc/fstab\ /etc/passwd\ /etc/group\ /etc/sysconfig/\ /etc/init.d/\ /etc/profile.local\ /etc/X11/XF86Config\ /etc/crontab\ /etc/xinetd.conf\ /etc/xinetd.d\ /etc/services\ /etc/dhcp.conf\ /etc/ntp.conf\ /etc/resolv.conf\ /etc/nsswitch.conf\ /etc/route.conf\ /etc/samba/\ /etc/httpd/\ /etc/pcmcia/network.opts\ /etc/lilo.conf\ /boot/grub/menu.lst\ /etc/modules.conf\ /etc/modules.conf.local\ /etc/modprobe.conf\ /etc/modprobe.conf.local\ /etc/hosts\ /etc/hosts.equiv\ /etc/hosts.allow\ /etc/hosts.deny\ /etc/hosts.equiv\ /etc/hosts.lpd\ /etc/exports\ /etc/networks\ /var/spool/fax/etc/config\ /var/spool/fax/etc/config.modem\ /var/spool/fax/etc/hosts.hfaxd\ /usr/local/bin/fax\ /etc/leafnode/config\ /etc/printcap\ /etc/ppp/options\ /etc/ppp/ip-up" > $LISTFILE echo "Archiving configuration data of $HOST to $LISTFILE ..." # We do NOT use absolute pathnmames. This is safer on extraction, # as you will have to be in '/' to accidently overwrite files ;-) # tar -czf /tmp/$ARCH.tgz -T $LISTFILE echo "Moving archive file to $FLOPPY ... " mv /tmp/$ARCH.tgz $FLOPPY || echo "Error occurred during copy!" && exit 1 # I don't know if sync is useful for floppies, but it won't hurt anyway ;-) sync sleep 1 sync umount $FLOPPY || echo "Error occurred during umount!" && exit 1 # Note: With these files, you may want to use interactive mode # while extracting, this is 'tar xwzf /floppy/archivename'. # (Extraction is relative to your actual directory). echo "Configuration files copied." echo "Finished; $FLOPPY is unmounted. You can remove it now." rm $LISTFILE exit 0 cleanup: exit 1