Page 1 of 1

Permissions error with cron pg_dump

PostPosted: Fri Sep 26, 2014 8:10 pm
by brossetti
Hello!

I'm putting the finishing touches on my omero installation and ran into a problem setting up my cron jobs. I followed the suggestions for setting up daily postgres backups with the example script:

Code: Select all
#!/bin/bash

DATE=`date '+%Y-%m-%d_%H:%M:%S-%Z'`
OUTPUT_DIRECTORY=/OMERO/backup/database
DATABASE="omero_database"
DATABASE_ADMIN="postgres"

mkdir -p $OUTPUT_DIRECTORY
chown -R $DATABASE_ADMIN $OUTPUT_DIRECTORY
su $DATABASE_ADMIN -c "pg_dump -Fc -f $OUTPUT_DIRECTORY/$DATABASE.$DATE.pg_dump $DATABASE"


I've set crontab to run this script (located in /home/omero/cron.omero/) as root, but I get the following error when it runs:

Code: Select all
could not change directory to "/root": Permission denied


I've looked around, but I'm not sure where this error is arising. The permissions of the directory with the script are "drwxr-xr-x omero omero" and the output directory permissions are "drwxrwxr-x postgres omero"

Thanks in advance for any suggestions!
Blair

Re: Permissions error with cron pg_dump

PostPosted: Mon Sep 29, 2014 8:19 am
by bpindelski
Hi Blair,

The error you are reporting is most probably related to using su. By default, this command tries to bring up an interactive shell in the name of the root user. I'm quite sure that the home directory for root doesn't exits, and that's why you get this error. What is surprising is that this still happens even when $DATABASE_ADMIN is provided as an argument.

I usually use sudo for executing any PostgreSQL CLI command on Unix-like operating systems.
I recommend you give this a try.

With kind regards,
Blazej

Re: Permissions error with cron pg_dump

PostPosted: Wed Oct 01, 2014 4:22 pm
by brossetti
Hi Blazej,

Thank you very much for your insight. In the end, I decided to incorporate this script into my rsnapshot backup routine. In the process, the pgdump.sh script was moved to a different directory and is called using backup_script from rsnapshot. Apparently some magic happened during all of that and now I don't get the error message. This could mean that everything is working nicely or that rsnapshot is suppressing the error message. My guess is that I might have had a bug in my shell script somewhere that I unknowingly sorted out.

Thanks,
Blair