August 28th, 2002, 12:27 AM
I am planning to automate the backup procedure at periodic levels using cron. To generate dump files with a distinction each time, how can I append the date ?
pg_dump hris > hris2808021000.dmp
where hris2808021000.dmp has 28 aug 02, 10:00.
Is this possible to auto generate by something like ...
pg_dump hris > hris%date.dmp
Awaiting your response.
Thanks & Regards.
September 6th, 2002, 08:23 PM
I just figured this one out today:
pg_dump hris > hris.`date +%A-%b-%d-%Y`
Not the same format as yours but it's pretty slick.
September 8th, 2002, 12:41 PM
You could also create a script (shell, Perl, Python) and call that from your cron job. That way, you can do much more in your backup process, things like compress the file, FTP the backup file to another location, send an email to interested parties. You might also want to vacuum the db before or after backup, doing that in one cron call may not be that easy.
September 9th, 2002, 12:06 AM
Thanks for the replies !
That was pretty smart. Well, as I wanted a half hourly backup, I've configured it as follows...
1. created a table to store date in format ddmonyyyyhh24mi
2. update the table before the backup
3. use a select on the table and append the date to the destination file of pg_dump.
In practise, this will also result in loss of data for the past half an hour, depending on the time of failure.