[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Cron Issue



On Fri, Mar 18, 2005 at 08:53:13AM -0600, Brooks R. Robinson wrote:
Greetings List!
	Hey I have a cron issue I can't resolve.  I have a standalone Debian
machine that I use as a PostgreSQL server for a bunch of different
databases.  Up until a few weeks ago, this data really wasn't a critical,
but now it's become very important, so I need to back it up.  I had been
doing a simple dump in cron like so:

30 4 * * *      pg_dump -d FSDetail | gzip > /var/tmp/FSDetail.gz

	There are no problems with it, and if the system died, I figured that I'd
be able to either get to the actual database or to the backup, or recreate
it without too much headache.  But like I said, it's become critical.  I
would like automagic serialized backups so I want to do something like this:

cp /var/tmp/FSDetail.gz /backup/PostgreSQL/`date +FS%y%m%d.gz`

	This give me a file like FS050316.gz, FS050317.gz, etc.  The /backup
directory is an SMB share on a NAS server that is routinely backed up.
However if I put this into cron:

30 6 * * *      cp /var/tmp/FSDetail.gz /backup/PostgreSQL/`date
+FS%y%m%d.gz`
or
30 6 * * *      'cp /var/tmp/FSDetail.gz /backup/PostgreSQL/`date
+FS%y%m%d.gz`'
or
30 6 * * *      "cp /var/tmp/FSDetail.gz /backup/PostgreSQL/`date
+FS%y%m%d.gz`"
or even
30 8 * * *      cp /var/tmp/FSDetail.gz /backup/PostgreSQL/$(date
+FS%y%m%d).gz

	I get something similar to this:

/bin/sh: -c: line 1: unexpected EOF while looking for matching `''
/bin/sh: -c: line 2: syntax error: unexpected end of file

Try writing a simple bash script to do this. It isn't clear to me that cron can expand those shell commands. Write and test a small script and when that is working, add the script to cron.

Example:
#! /usr/bin/env bash
FOLDER="/backup/PostgreSQL"
FILE=$(date +FS%y%m%d.gz)
cp /var/tmp/FSDetail.gz $FOLDER/$FILE

Good luck.

--
Steve Block
http://ev-15.com/
http://www.steveblock.com/
scblock@ev-15.com



Reply to: