Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Using date/time variables in cronjobs?
Date: Sun, 05 May 2013 17:49:45
Message-Id: 51869BA5.9030206@gmail.com
In Reply to: [gentoo-user] Using date/time variables in cronjobs? by Tanstaafl
1 On 05/05/2013 18:56, Tanstaafl wrote:
2 > Ok, another little thing...
3 >
4 > Is there a simple way to use date/time variables in cronjobs? Or do I
5 > need to use a bash script for this? I prefer simple, and just using the
6 > variables directly in the cron command would be easier if it works, so
7 > figured I'd ask first...
8 >
9 > I'm trying to schedule a dump of my databases like so:
10 >
11 > pg_dumpall --username=username -o -f
12 > /home/user/mypg_backups/hourly/\%y/\%m/\%d/\%t.sql.gz
13 >
14 > But trying to run this command fails with:
15 >
16 > pg_dumpall: could not open the output file
17 > "/home/user/mypg_backups/hourly/%y/%m/%d/%t.sql.gz": No such file or
18 > directory
19 >
20 > Tried escaping the variables and not, same error...
21
22
23 What creates those variables %y etc? They don't "just exist", something
24 sets them. Check that that thing sets them correctly.
25
26 But I'll bet the directory /home/user/mypg_backups/hourly/\%y/\%m/\%d/
27 doesn't exist. pg_dumpall won;t create it, that's your job.
28
29 So now you need a test that the directory exists, mkdir -p it if not,
30 and only then write the output file. Which is far easier done in a
31 wrapper script than in a one-liner, if only for the fact that you have
32 indented text.
33
34 Sometimes, making things simpler makes your life harder. This looks like
35 such a case.
36
37
38 --
39 Alan McKinnon
40 alan.mckinnon@×××××.com