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