如何通过密码对pg_dump? [英] How to pass in password to pg_dump?

查看:347
本文介绍了如何通过密码对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文件:见<一href=\"http://www.postgresql.org/docs/current/static/libpq-pgpass.html\">http://www.postgresql.org/docs/current/static/libpq-pgpass.html对于格式的详细信息(包括最后对在那里解释,如果你不将模式设置为0600,将被忽略)。

Create a .pgpass file in the home directory of the account that pg_dump will run as: see http://www.postgresql.org/docs/current/static/libpq-pgpass.html for details of the format (including the last para where it explains it will be ignored if you don't set the mode to 0600).

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

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