9

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.

3 Answers 3

25

Try this:

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

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

Sign up to request clarification or add additional context in comments.

Comments

4

Use backticks and the date command.

i.e.

pg_dump prod-db -U postgres > prod-db-`date +%d-%m-%y`.sql 

Comments

0
pg_dump --file="{data_source}-{timestamp}-dump.sql"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.