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請參閱我編輯的答案。 –