Backup script

From: Jon Reynolds <jonr@destar.net>
Date: Tue Jan 24 2006 - 15:36:43 AKST

Hello,

I have this little backup script that backs up our mail logs and zips
them and stores them in a folder. It works almost perfectly except that
it also saves the same compressed file in /root as well as
/mnt/backup/bms/. I cannot figure out why it saves it in the /root
directory also.

Am I missing something simple here?

Jon

This is in my crontab:

58 23 * * * root /mnt/backup/bms

And this is my script:

#!/bin/bash
## This is the famous "sha-bang" statement,
## that tells the shell which command
## interpreter to use. See man magic
## to learn the inner workings of sha-bang.
## this script uses the tar, mkdir, and cp commands
## plus Bash's conditional statements
## smart admins write lots of comments

# test for existing backup directory
# if it does not exist, create it
# -e is the Bash way of asking "does this file exist"
# $ means variable substitution. HOME is a builtin
# Bash variable.
if [ -e /mnt/backup ]
then
echo "The backup directory exists."
else
echo "A backup directory does not exist, and will be created."
mkdir /mnt/backup
echo "A backup directory has been created"
fi

# now we define our own variables
# location of files to backup
FILES=/home/e-smith/files/users/maillog/Maildir/new/

# name of compressed archive
ARCHIVENAME="maillog_`date +%d%b%Y`.tgz"

# location of backup directory
BACKUPDIR=/mnt/backup

# create compressed archive, copy to backup directory
tar czf $ARCHIVENAME $FILES
cp -ap $ARCHIVENAME $BACKUPDIR

##########################Taken from xargs man page########################

#find /tmp -name core -type f -print | xargs /bin/rm -f

# Find files named core in or below the directory /tmp and delete them.
# Note that this will work incorrectly if there are any filenames
containing
# newlines or spaces.

find $FILES -name '*' -type f -print0 | xargs -0 /bin/rm -f

# Find files named *(anything) in or below the directory defined in
our $FILES variable above and delete them, processing
# filenames in such a way that file or directory names containing spaces
or newlines are correctly handled.

############################################################################

#rm -f $FILES/* <--This would produce 'Argument list too long.' error.
# The above find solves this problem.

if [ -e $BACKUPDIR/$ARCHIVENAME ]
then
echo "This backup is clean."
else
echo "The backup failed. Time to debug."
fi
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Jan 24 15:37:09 2006

This archive was generated by hypermail 2.1.8 : Tue Jan 24 2006 - 15:37:09 AKST