backup shell script
Name: Backup Shell Script
Language: /bin/bash
API: OpenGL
Platform: Linux/Solaris
#!/bin/bash
#
# backup - simple backup script for all system users
#
# - look up anyone with a home dir
# - tar there dir into a backup location
# only updating the last tar file if
# necissary
# - This would get run by cron on whatever
# interval was deemed necissary
#
# Version 1.0 - Corey Auger
# corey@coreyauger.com
#
# set the path like a good little monkey
PATH=/bin:/usr/bin:/sbin:/usr/sbin
# set the location of file swe are using in the program
PASSWD=/etc/passwd # passwd file
BACKDIR=$HOME/backups # location of backup dir
USER=<username># ftp user name
FTPUSER=<username># ftp user name
FTPPASS=<pass> # ftp password
FTPDIR=ftp://ftp.cpsc.ucalgary.ca/www # ftp location
# chech if we can find the passwd file with read access
if ! [ -r $PASSWD ]; then
echo "$PASSWD does not exist or acess is denied"
exit 1
fi
# check if backup dir exists.. if not create it
if ! [ -d $BACKDIR ]; then
mkdir $BACKDIR
fi
# for every user that has a home directory
for homedir in `cat $PASSWD | grep "$USER" | awk -F: '{ print $6 }'`
do
if ! [ -f $BACKDIR/test.tar ]; then # see if there is a backup file there
# no backup found so create a new one
tar -cvvf $BACKDIR/test.tar $homedir/www 2> /dev/null 1> /dev/null
continue
fi
# found a backup file so lets update it
tar -uvf $BACKDIR/test.tar $homedir/bin 2> /dev/null 1> /dev/null
done
# check if we have lftp ( linux default ftp ... diferent syntax is needed then )
LFTP=$(which lftp | grep "lftp")
if [ -n "$LFTP" ]; then
# use lftp since the system located it
lftp -u $FTPUSER,$FTPPASS $FTPDIR 2>> $BACKDIR/ftperr 1> $BACKDIR/ftpnorm <
mput $BACKDIR/*
quit
FTP_SCRIPT
else
# use normal ftp since we dont have lftp
ftp -n $FTPDIR 2>> $BACKDIR/ftperr 1> $BACKDIR/ftpnorm <
user $USER $PASSWD
mput $BACKDIR/*
quit
FTP_SCRIPT
fi
# check the return code from ftp
if [ $? ]
mail -u su-root -s "backup script ftp fail" su-root #change to mail function
fi
exit 0
|