Just closing out this thread...
Thanks to your and Neill and others' help, I've settled on this for my
nightly job, that also deletes the oldest hourly's and daily over a
certain number to keep:
#!/bin/bash
BACKUP_DIR="/my/backups/app/sql/nightly"
BACKUP_DIR_hourly="/my/backups/app/sql/hourly"
PGUSER="SuperUser"
PG_my_app=`date '+%Y-%m-%d_%H:%M-app'`
/usr/bin/pg_dumpall -U $PGUSER -o -f $BACKUP_DIR/$PG_my_app-sql.gz
rm -f $(ls -1t $BACKUP_DIR/* | tail -n +91)
rm -f $(ls -1t $BACKUP_DIR_hourly/* | tail -n +36)
I'd like to learn how to do proper error detection using if/fi
branching, but that will be a lesson for another day. I'll be monitoring
these on a daily basis, so will hopefully catch any real problems before
they cause any real problems.
Thanks again to all who helped me get these functional.
On 2013-05-05 11:25 PM, Pandu Poluan <[email protected]> wrote:
In bash, underscores can be part of a variable name.
$PGdd_$PGtt involves two variables: $PGdd_ (note the trailing
underscore) and $PGtt
You should write it like this:
${PGdd}_$PGtt
The { } syntax is bash's way to indicate what exactly constitutes a
variable name. IOW, the above construct has three parts: the variable
$PGdd, an underscore, and the variable $PGtt
Whenever you want to 'run' a variable name (i.e., combine it with other
characters without specifying a whitespace), you should always use
braces { } around the variable name.
That said, since you're no longer creating a directory structure, why
don't you just output everything using a single 'date' command? E.g. :
date +'mypg-%Y-%m-%d_%H:%M'