0
我有下面的postgres备份脚本,它是一个shell脚本并且被编写为运行ans postgres
用户。但是问题是postgres
用户没有权限写这些目录。我作为用户在这些机器上没有sudo
,但我已将目录更改为拥有755并添加到具有读写执行权限的组之一。由于postgres
用户不是unix
用户组的一部分,我想我遇到了这个问题。权限问题:创建postgres回作为postgres用户
我的目标是把这个cron的标签,但在此之前,我需要拿到剧本具有适当权限运行:
#!/bin/bash
# location to store backups
backup_dir="/location/to/dir"
# 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
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do
if [ "$i" != "template0" ] && [ "$i" != "template1" ]; then
echo Dumping $i to $backup_dir$i\_$backup_date
pg_dump -Fc $i > $backup_dir$i\_$backup_date
fi
done
find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \;
保罗帕诺我想出了一个办法做到这一点实际上并没有使用Postgres的用户,我可以作为数据库管理员,但这个问题上运行pg_dump的是'的pg_dump -Fc -Uga_db_admin MyDatabase的 - 密码> $ BACKUP_DIR \ _ $ backup_date' shell脚本会提示输入密码,以避免这种情况。 –
@ find-missing-semicolon请参阅我编辑的答案。 –