Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PostgreSQL backup files with timestamp

I'm doing a dump like this pg_dump prod-db -U postgres > prod-db.sql, but would be cool if I could do a dump like pg_dump prod-db -U postgres > prod-db-{date}.sql and be able to generate a file like prod-db-06-02-13.sql via shell...
I have no idea on how to start nor where to looking for. Any ideas, links, docs would be much appreciated.

like image 262
Luiz E. Avatar asked Feb 06 '13 11:02

Luiz E.


2 Answers

Try this:

pg_dump prod-db -U postgres > prod-db-$(date +%d-%m-%y).sql

Here's the date manual, for other format options.

like image 117
Anton Kovalenko Avatar answered Nov 09 '22 18:11

Anton Kovalenko


Use backticks and the date command.

i.e.

pg_dump prod-db -U postgres > prod-db-`date +%d-%m-%y`.sql 
like image 3
Ed Heal Avatar answered Nov 09 '22 17:11

Ed Heal