1

I would like to dump postgres database and make it periodical with crontab.

so I tried to run the following in a bash script:

sudo -u postgres pg_dump --dbname=postgresql://django:mypass@127.0.0.1:5432/django

I get this:

-bash: !: event not found

probably because there are special characters in the password. how to escape from special characters? how can I pass the password parameter? is there any other way to auto dump periodically from postgresql.

schism11
  • 11
  • 1
  • Related: https://stackoverflow.com/q/6405127/330315 –  Apr 10 '18 at 11:53
  • Yes, the better option is to use a .pgpass file instead, otherwise the password will be visible when you list processes with `ps aux` – Uku Loskit Apr 10 '18 at 11:59

1 Answers1

0

You must encode the special characters.

If your password is a!b@c , the command would be

sudo -u postgres pg_dump --dbname=postgresql://django:a%21b%40c@127.0.0.1:5432/django
JGH
  • 15,928
  • 4
  • 31
  • 48