On 05/05/2013 18:56, Tanstaafl 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...
What creates those variables %y etc? They don't "just exist", something sets them. Check that that thing sets them correctly. But I'll bet the directory /home/user/mypg_backups/hourly/\%y/\%m/\%d/ doesn't exist. pg_dumpall won;t create it, that's your job. So now you need a test that the directory exists, mkdir -p it if not, and only then write the output file. Which is far easier done in a wrapper script than in a one-liner, if only for the fact that you have indented text. Sometimes, making things simpler makes your life harder. This looks like such a case. -- Alan McKinnon alan.mckin...@gmail.com