On 2013-05-05 5:25 PM, Neil Bothwick <n...@digimed.co.uk> wrote:
On Sun, 5 May 2013 16:06:45 -0400, Todd Goodman wrote:

mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd
/usr/bin/pg_dumpall -U $PGUSER -o | \
         gzip >$BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz

You could have it check first and only do the mkdir if the directory
didn't already exist:

[[ -d $BACKUP_DIR/$PGyy/$PGmm/$PGdd ]] || \
         mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd

You could, but it is redundant as mkdir already does that test when
invoked with -p.

Many thanks for the short noob bash scripting tutorial guys. Obviously I'm very new to it.

I did confirm that there was no need to test (thanks Neil, this will come in handy I'm sure), but I also decided to uncomplicate it and just dump all fo the backups in a single directory. I realized this isn't like my email backups where I will be keeping years of them. I'll probably only keep 30 or so.

So, my final script looks like this:

#!/bin/bash
BACKUP_DIR="/home/user/mypg_backups"
PGUSER="superuser"
PGyy=`date '+%Y'`
PGmm=`date '+%m'`
PGdd=`date '+%d_'`
PGtt=`date '+%H:%M'`
/usr/bin/pg_dumpall -U $PGUSER -o -f $BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd$PGtt.gz

For some reason, if I put the underscore in the filename itself, ie:

$BACKUP_DIR/mypg-$PGyy-$PGmm-$PGdd_$PGtt.gz

It omitted the $PGdd variable entirely.

I had to add the underscore into the variable to get the output like I wanted. Weird...

Anyway, this is working perfectly, thanks guys.

Reply via email to