#!/bin/sh # -*-Shell-script-*- # # This script Excerpted From: # --------------------------- # From: Aaron Lehmann # To: Rick Moen # Cc: svlug@svlug.org # Subject: Re: [svlug] Tape backup software survey # Date: Sun, 20 May 2001 16:28:12 -0700 # # # debbackup - A backup script for debian systems # Copyright (C) 2000 Aaron Lehmann # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. BACKUPFILENAME=/etc/debbackup.conf BADIRS="/home /etc" run_script() { # Import configuration variables from /etc/debbackup.conf . $BACKUPFILENAME # make sure all of the variables from the conf file are set if [ x$RSYNCHOST = x ] || [ x$RSYNCMODULE = x ]; then # [ x$EMAILADDR = x ] echo "The debbackup configuration file exists, but it is not fully configured."; echo "Try running with the -configure option to set it up."; exit 1; fi if [ x$HOSTNAME = x ] ; then HOSTNAME=`hostname`; fi # First check sanity of system. If /home is empty, don't be happy if [ `ls /home/ | wc -l | awk '{print $1}'` = 0 ] ; then echo "Backup failed: /home is empty. User directories are only supported"; echo "in /home for the time being. Sorry."; exit 1; fi # save selections TMPFILENAME=`tempfile` dpkg --get-selections | awk '$2 == "install" { print }' > $TMPFILENAME rsync -azq $TMPFILENAME ${RSYNCHOST}::${RSYNCMODULE}/$HOSTNAME/selections rm -f $TMPFILENAME # set up --excludes arg if [ ! x$EXCLUDES = x ] ; then EXCLUDEARG=`(echo -n ' ' ; echo $EXCLUDES ) | sed 's/ / --exclude /g'` fi # take into account additional files, if any if [ ! x$BAADDITIONAL = x ] ; then BADIRS="$BADIRS $BAADDITIONAL"; fi # back up rsync -azq --delete $EXCLUDEARG $BADIRS ${RSYNCHOST}::${RSYNCMODULE}/$HOSTNAME/ exit 0; } config_client() { echo "I'm going to ask you a few questions. Your answers will be used to"; echo "configure debbackup for a machine which is to be backed up."; echo "Note that this configurator will probably only work when running as root."; echo "Proceeding will overwrite your configuration for debbackup."; echo -n "Continue? [Y/n] "; read CONTINUECHOICE case $CONTINUECHOICE in y|Y|'' ) ;; * ) exit 0 ;; esac echo "OK, starting interrogation."; echo ; (echo '# debbackup configuration file' ; echo ) > $BACKUPFILENAME; # DEFAULT=root # echo -n "1) Your e-mail address (for error notification) [$DEFAULT]: "; # read CHOICE # if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi # echo "EMAILADDR='$CHOICE'" >> $BACKUPFILENAME; DEFAULT=192.168.1.1 echo -n "1) rsync server to back up to [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "RSYNCHOST='$CHOICE'" >> $BACKUPFILENAME; DEFAULT=backup echo -n "2) rsync module on server to back up to [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "RSYNCMODULE='$CHOICE'" >> $BACKUPFILENAME; DEFAULT= echo -n "3) Additional files to back up [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "BAADDITIONAL='$CHOICE'" >> $BACKUPFILENAME; DEFAULT= echo "4) Path names (shell globs allowed) to exculde (seperated by" echo -n " spaces) [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "EXCLUDES='$CHOICE'" >> $BACKUPFILENAME; chmod 755 $BACKUPFILENAME; echo "Configuration complete. Congratulations!"; echo ; echo -n "Would you like to add a cron job to backup on a regular basis? [Y/n] "; read CHOICE case $CHOICE in y|Y|'' ) ;; * ) exit 0 ;; esac CRONLINE=`crontab -l 2>/dev/null | grep debbackup` if [ $? = 0 ] ; then echo "You appear to already have a crontab entry for debbackup:" echo " $CRONLINE"; echo "Please remove it manually before continuing." echo -n "Continue? [N/y]: " read CHOICE case $CHOICE in y|Y ) ;; * ) exit 1 ;; esac fi DEFAULT='/usr/sbin/debbackup' echo -n "Full path to the debbackup script? [$DEFAULT]: "; read DEBBPATH if [ x$DEBBPATH = x ] ; then DEBBPATH=$DEFAULT; fi echo "For any of the following questions, you may enter '*'," echo "meaning \"all possible values\"."; echo ; DEFAULT='*' echo -n "During which months should debbackup be run (1-12)? [$DEFAULT]: "; read MONTHS if [ x$MONTHS = x ] ; then MONTHS=$DEFAULT; fi DEFAULT='*' echo -n "During which days of the month (1-31)? [$DEFAULT]: "; read DAYSM if [ x$DAYSM = x ] ; then DAYSM=$DEFAULT; fi DEFAULT='1' echo -n "During which days of the week (1-7)? [$DEFAULT]: "; read DAYSW if [ x$DAYSW = x ] ; then DAYSW=$DEFAULT; fi DEFAULT='5' echo -n "At which hour (0-24)? [$DEFAULT]: "; read HOURS if [ x$HOURS = x ] ; then HOURS=$DEFAULT; fi DEFAULT='30' echo -n "At which minute (0-59)? [$DEFAULT]: "; read MINUTES if [ x$MINUTES = x ] ; then MINUTES=$DEFAULT; fi echo -n "At which microsecond (0-999999)? [0]: "; sleep 1; echo ; echo "Just kidding!"; echo ; echo "$MINUTES $HOURS $DAYSM $MONTHS $DAYSW $DEBBPATH" | crontab - echo "Cron job installed:"; echo " $MINUTES $HOURS $DAYSM $MONTHS $DAYSW $DEBBPATH"; echo "Remember, you can always modify it using \"crontab -e\"."; exit 0; } config_server() { echo "I'm going to ask you a few questions. Your answers will be used to"; echo "configure rsync on a server which will recieve backups from clients."; echo "Note that this configurator will probably only work when running as root."; echo "This configurator will attempt to append to your /etc/rsyncd.conf file."; echo -n "Continue? [Y/n] "; read CONTINUECHOICE case $CONTINUECHOICE in y|Y|'' ) ;; * ) exit 0 ;; esac echo "OK, starting interrogation."; echo ; RSYNCCONFFILENAME=/etc/rsyncd.conf- cp -f /etc/rsyncd.conf $RSYNCCONFFILENAME echo >> $RSYNCCONFFILENAME; echo "# The following module created by debbackup" >> $RSYNCCONFFILENAME; DEFAULT=backup echo -n "1) rsync module name to configure [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "[$CHOICE]" >> $RSYNCCONFFILENAME; DEFAULT=/home/backup echo -n "2) Path to directory to store backups [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi if [ ! -d $CHOICE ] ; then echo "This file does not exist or is not a directory."; echo "I'm creating it at $CHOICE."; echo "Please verify that it has been created after this configuration is complete."; mkdir -p $CHOICE; fi echo "path=$CHOICE" >> $RSYNCCONFFILENAME; STORAGEDIR=$CHOICE echo -n "3) Hosts to allow backups from: "; read CHOICE echo "hosts allow=$CHOICE" >> $RSYNCCONFFILENAME; DEFAULT=nobody echo -n "4) User that will own the $STORAGEDIR directory [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi chown $CHOICE $STORAGEDIR; echo "uid=$CHOICE" >> $RSYNCCONFFILENAME; DEFAULT=root echo -n "5) Group for the $STORAGEDIR directory [$DEFAULT]: "; read CHOICE if [ x$CHOICE = x ] ; then CHOICE=$DEFAULT; fi echo "gid=$CHOICE" >> $RSYNCCONFFILENAME; chgrp $CHOICE $STORAGEDIR; echo "read only=no" >> $RSYNCCONFFILENAME; echo "use chroot=yes" >> $RSYNCCONFFILENAME; chmod 644 $RSYNCCONFFILENAME; mv $RSYNCCONFFILENAME /etc/rsyncd.conf; echo "Configuration complete. Congratulations!"; echo "Make sure that the rsync daemon is running or will be run from inetd."; echo "See the rsync documentation for more instructions."; exit 0; } config_unknown() { # find out which we should use: dialog or whiptail #MESSAGEAPP=`type -p dialog` #if [ x$MESSAGEAPP = x ] ; then # MESSAGEAPP=`type -p whiptail` # if [ x$MESSAGEAPP = x ] ; then # echo "Fatal error: can not find dialog or whiptail"; # exit 1; # fi #fi echo "Would you like to configure debbackup for a:"; echo " c: Client"; echo " s: Server"; echo " q: Neither. I don't want to configure debbackup right now." echo -n "Please enter your choice [c, s, q]: "; read CHOICE case $CHOICE in c ) config_client ;; s ) config_server ;; * ) echo "debbackup not configured. Come back soon!" ;; esac } display_help() { echo "$0 [-help]"; echo " Display this help text"; echo "$0 [-configure]"; echo " Run a step-by-step configurator for a client or server"; echo "$0"; echo " Back up files if previously configured as a client."; echo " Otherwise, run the configurator."; } case $1 in -configure ) config_unknown ;; -help|-h ) display_help ;; '' ) if [ ! -f $BACKUPFILENAME ] ; then echo "You don't seem to have debbackup configured."; config_unknown ; fi run_script ;; * ) display_help ;; esac _______________________________________________ svlug mailing list svlug@lists.svlug.org http://lists.svlug.org/mailman/listinfo/svlug