如何将密码传递给 pg_dump? [英] How to pass in password to pg_dump?

查看:36
本文介绍了如何将密码传递给 pg_dump?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天晚上都在尝试创建一个 cronjob 来备份我的数据库,以免发生灾难性事件.看起来这个命令应该满足我的需求:

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 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz

除了运行之后,它希望我输入密码.如果我从 cron 运行它,我就不能这样做.如何自动传入一个?

Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can I pass one in automatically?

推荐答案

pg_dump 将运行的帐户的主目录中创建一个 .pgpass 文件.

Create a .pgpass file in the home directory of the account that pg_dump will run as.

格式为:

hostname:port:database:username:password

然后,将文件的模式设置为0600.否则,它将被忽略.

Then, set the file's mode to 0600. Otherwise, it will be ignored.

chmod 600 ~/.pgpass

查看 Postgresql 文档 libpq-pgpass 了解更多详情.

See the Postgresql documentation libpq-pgpass for more details.

这篇关于如何将密码传递给 pg_dump?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆