RE: Backup script

From: captgoodnight captgoodnight <captgoodnight@hotmail.com>
Date: Tue Jan 24 2006 - 18:09:55 AKST

I'll bite.

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

this is being executed in /root

#!/bin/bash

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

If the directory doesn't exist, how can the script /mnt/backup/bms exist?
May not need that block...

FILES=/home/e-smith/files/users/maillog/Maildir/new/

ARCHIVENAME="maillog_`date +%d%b%Y`.tgz"

BACKUPDIR=/mnt/backup

tar czf $ARCHIVENAME $FILES
cp -ap $ARCHIVENAME $BACKUPDIR

leaves behind the initial one here, executing path being /root. You can
remove the p since a covers it...

                                if not the executing directory, then

then the script would be run from /mnt/backup/ and would just overwrite what
it created already...

So, the question is, does this job /mnt/backup/bms
get executed from /root? or /mnt/backup/? I say /root :) It makes sense to
be /root.

http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/custom-guide/cron-task.html

--bests,
eddie

>From: Jon Reynolds <jonr@destar.net>
>Reply-To: jonr@destar.net
>To: AK Lug Mailing List <aklug@aklug.org>
>Subject: Backup script
>Date: Tue, 24 Jan 2006 15:36:43 -0900
>
>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.
>

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Jan 24 18:10:16 2006

This archive was generated by hypermail 2.1.8 : Tue Jan 24 2006 - 18:10:17 AKST