我想创建一个 postgres 备份脚本,但我不想使用 postgres 用户,因为我所在的 unix 系统几乎没有限制。我想要做的是在 crontab 上以 unix 系统(网络)的普通用户身份运行此脚本,并在脚本中使用数据库管理员帐户。
只是为了在 unix 系统(网络)中说清楚,我有 user foo
,现在我们有postgres
默认 postgres 用户的 user ,然后对于数据库,我们有一个 database admin user my_db_admin
。foo
我使用脚本中my_db_admin
的用户和凭据编写脚本以网络用户身份执行。
这是我开始的,但问题是当我执行脚本时,它给出了一个错误,说没有提供密码。
#!/bin/bash
export PASSWORD="MyPassword"
backup_dir="/BACKUP/LOCATION"
# name of the backup file has the date
backup_date=`date +%d-%m-%Y`
# only keep the backup for 30 days (maintain low storage)
number_of_days=30
pg_dump -Fc -Umy_db_admin MyDatabase -w > $backup_dir\_$backup_date
find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \;
这是错误:
pg_dump: [archiver (db)] connection to database "MyDatabase" failed: fe_sendauth: no password supplied