1 |
* Tanstaafl <tanstaafl@×××××××××××.org> [130505 14:32]: |
2 |
> On 2013-05-05 2:18 PM, Neil Bothwick <neil@××××××××××.uk> wrote:> On |
3 |
> Sun, 05 May 2013 14:07:50 -0400, Tanstaafl wrote: |
4 |
> >> /home/user/mypg_backups/2013/May/Sun/pg_all-13:54.gz: No such file or |
5 |
> >> directory |
6 |
> >> |
7 |
> >> So, it is expanding the variables properly, but apparently won't |
8 |
> >> automatically create the directories? Is there some kind of flag |
9 |
> >> I can add to the command to do that? |
10 |
> |
11 |
> > mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd/ |
12 |
> |
13 |
> Thanks Neill... |
14 |
> |
15 |
> Tried changing the command in the script to: |
16 |
> |
17 |
> > /usr/bin/pg_dumpall -U $PGUSER -o | gzip > mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz |
18 |
> |
19 |
> and got this error: |
20 |
> |
21 |
> # ./ecat_pgdump.sh |
22 |
> gzip: invalid option -- 'p' |
23 |
> |
24 |
> Tried putting quotes around it like this: |
25 |
> |
26 |
> > /usr/bin/pg_dumpall -U $PGUSER -o | gzip > "mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz" |
27 |
> |
28 |
> and got the original error with the added 'mkdir -p': |
29 |
> |
30 |
> # ./mypg_pgdumpall.sh |
31 |
> ./mypg_pgdumpall.sh: line 10: mkdir -p |
32 |
> /home/user/mypg_backups/2013/May/Sun/ecat-14:26.gz: No such file or |
33 |
> directory |
34 |
> |
35 |
> I'm guessing I just need to know where to put the quotes? |
36 |
|
37 |
You can't put it in that line. Put it on it's own line before the |
38 |
pg_dumpall line: |
39 |
|
40 |
mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd |
41 |
/usr/bin/pg_dumpall -U $PGUSER -o | \ |
42 |
gzip >$BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz |
43 |
|
44 |
You could have it check first and only do the mkdir if the directory |
45 |
didn't already exist: |
46 |
|
47 |
[[ -d $BACKUP_DIR/$PGyy/$PGmm/$PGdd ]] || \ |
48 |
mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd |