add*_*ons 3 postgresql shell pg-dump
我想创建一个postgres备份脚本,但我不想使用postgres用户,因为我所使用的unix系统几乎没有限制.我想要做的是在crontab上以unix系统(网络)的常规用户身份运行此脚本,并在脚本中使用数据库管理员帐户.
为了在unix系统(网络)中明确我有用户foo,现在我们有postgres默认postgres用户的用户,然后对于数据库我们有一个数据库管理员用户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 {} \;
Run Code Online (Sandbox Code Playgroud)
这是错误:
pg_dump: [archiver (db)] connection to database "MyDatabase" failed: fe_sendauth: no password supplied
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6725 次 |
| 最近记录: |