How to pass in password to pg_dump?

后端 未结 16 830
深忆病人
深忆病人 2020-11-28 00:58

I\'m trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs:

0          


        
16条回答
  •  余生分开走
    2020-11-28 01:32

    the easiest way in my opinion, this: you edit you main postgres config file: pg_hba.conf there you have to add the following line:

    host 127.0.0.1/32 trust

    and after this you need start you cron thus:

    pg_dump -h 127.0.0.1 -U | gzip > /backup/db/$(date +%Y-%m-%d).psql.gz

    and it worked without password

提交回复
热议问题