1 |
Ok, some of those variables were wrong (copy pasted from my first |
2 |
brain-dead attempt)... |
3 |
|
4 |
I now have a rudimentary bash script with contents: |
5 |
|
6 |
#!/bin/bash |
7 |
BACKUP_DIR="/home/user/mypg_backups" |
8 |
PGUSER="superuser" |
9 |
PGtt=`date '+%H:%M'` |
10 |
PGhr=`date '+%H'` |
11 |
PGdd=`date '+%a'` |
12 |
PGmm=`date '+%b'` |
13 |
PGyy=`date '+%Y'` |
14 |
/usr/bin/pg_dumpall -U $PGUSER -o | gzip > |
15 |
$BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz |
16 |
|
17 |
Running this results in: |
18 |
|
19 |
# ./mypg_pgdumpall.sh |
20 |
./mypg_pgdumpall.sh: line 10: |
21 |
/home/user/mypg_backups/2013/May/Sun/pg_all-13:54.gz: No such file or |
22 |
directory |
23 |
|
24 |
So, it is expanding the variables properly, but apparently won't |
25 |
automatically create the directories? Is there some kind of flag I can |
26 |
add to the command to do that? |
27 |
|
28 |
Running the bare command without the variables works as expected, so it |
29 |
is just a matter of getting the directories auto created if they don't |
30 |
already exist. |
31 |
|
32 |
Is there a reasonably easy way of doing this? |
33 |
|
34 |
On 2013-05-05 12:56 PM, Tanstaafl <tanstaafl@×××××××××××.org> wrote: |
35 |
> Ok, another little thing... |
36 |
> |
37 |
> Is there a simple way to use date/time variables in cronjobs? Or do I |
38 |
> need to use a bash script for this? I prefer simple, and just using the |
39 |
> variables directly in the cron command would be easier if it works, so |
40 |
> figured I'd ask first... |
41 |
> |
42 |
> I'm trying to schedule a dump of my databases like so: |
43 |
> |
44 |
> pg_dumpall --username=username -o -f |
45 |
> /home/user/mypg_backups/hourly/\%y/\%m/\%d/\%t.sql.gz |
46 |
> |
47 |
> But trying to run this command fails with: |
48 |
> |
49 |
> pg_dumpall: could not open the output file |
50 |
> "/home/user/mypg_backups/hourly/%y/%m/%d/%t.sql.gz": No such file or |
51 |
> directory |
52 |
> |
53 |
> Tried escaping the variables and not, same error... |
54 |
> |