Ok, some of those variables were wrong (copy pasted from my first
brain-dead attempt)...
I now have a rudimentary bash script with contents:
#!/bin/bash
BACKUP_DIR="/home/user/mypg_backups"
PGUSER="superuser"
PGtt=`date '+%H:%M'`
PGhr=`date '+%H'`
PGdd=`date '+%a'`
PGmm=`date '+%b'`
PGyy=`date '+%Y'`
/usr/bin/pg_dumpall -U $PGUSER -o | gzip >
$BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz
Running this results in:
# ./mypg_pgdumpall.sh
./mypg_pgdumpall.sh: line 10:
/home/user/mypg_backups/2013/May/Sun/pg_all-13:54.gz: No such file or
directory
So, it is expanding the variables properly, but apparently won't
automatically create the directories? Is there some kind of flag I can
add to the command to do that?
Running the bare command without the variables works as expected, so it
is just a matter of getting the directories auto created if they don't
already exist.
Is there a reasonably easy way of doing this?
On 2013-05-05 12:56 PM, Tanstaafl <tansta...@libertytrek.org> wrote:
Ok, another little thing...
Is there a simple way to use date/time variables in cronjobs? Or do I
need to use a bash script for this? I prefer simple, and just using the
variables directly in the cron command would be easier if it works, so
figured I'd ask first...
I'm trying to schedule a dump of my databases like so:
pg_dumpall --username=username -o -f
/home/user/mypg_backups/hourly/\%y/\%m/\%d/\%t.sql.gz
But trying to run this command fails with:
pg_dumpall: could not open the output file
"/home/user/mypg_backups/hourly/%y/%m/%d/%t.sql.gz": No such file or
directory
Tried escaping the variables and not, same error...