Link to home
Start Free TrialLog in
Avatar of motioneye
motioneyeFlag for Singapore

asked on

Postgresql - Failed to run backup file *.sh from Postgresql Enterprise Manager

I tried to run a file below in PostgreSQL Enterprise Manager, it show successful but the backup file was not get created.

Then I try to run it from the terminal which it prompt me below error messages


-bash-4.1$ sh dailybackup.sh
dailybackup.sh: line 11: /usr/bin/pg_dumpall: No such file or directory
dailybackup.sh: line 11: /opt/PostgresPlus/Backup/fullbackup-201309.sql.gz: Permission denied
dailybackup.sh: line 18: /usr/bin/pg_dump: No such file or directory
dailybackup.sh: line 18: /usr/bin/pg_dump: No such file or directory
-bash-4.1$


Below heer is the script for backups

#!/bin/bash
#backup directory can be a file server share that the PgAgent daemon account has access to
BACKUPDIR="/opt/PostgresPlus/Backup"
PGHOST="localhost"
PGUSER="postgres"
PGBIN="/usr/bin"
thedate=`date --date="today" +%Y%m%d%H`
themonth=`date --date="today" +%Y%m`

#create a full backup of the server databases
$PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip > $BACKUPDIR/fullbackup-$themonth.sql.gz

#put the names of the databases you want to create an individual backup below
dbs=(DB1 DB1Snapshot )
#iterate thru dbs in dbs array and backup each one
for db in ${dbs[@]}
do
      $PGBIN/pg_dump -i -h $PGHOST -U $PGUSER -F c -b -v -f $BACKUPDIR/$db-$thedate.compressed $db
done

#this section deletes the previous month of same day backup except for the full server backup
rm -f $BACKUPDIR/*`date --date="last month" +%Y%m%d`*.compressed
Avatar of farzanj
farzanj
Flag of Canada image

This command appears to have a problem

Issue command
ls -l  /usr/bin/pg_dumpall

Open in new window


Also
ls -ld /opt/PostgresPlus/Backup
ls -l  /usr/bin/pg_dump

Open in new window


Show the results
SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of motioneye

ASKER

Thanks,
I have managed a correct location for the backup. I just wondering one thing.

when I ran the sh script from command line in Linux its working to save a backups, howeveer it prompt me for password when it require access to the database.

I did a same thing from enterprise db manager, but it does not backups any database using the same screen. do you guys have any ideas why it happens ??

Below is the script

#!/bin/bash
#backup directory can be a file server share that the PgAgent daemon account has access to
BACKUPDIR="/opt/PostgresPlus/Backup"
PGHOST="localhost"
PGUSER="postgres"
PGBIN="/opt/PostgresPlus/9.2AS/bin"
thedate=`date --date="today" +%Y%m%d%H`
themonth=`date --date="today" +%Y%m`

#create a full backup of the server databases
$PGBIN/pg_dumpall -p5432  -h $PGHOST -U $PGUSER | gzip > $BACKUPDIR/fullbackup-$themonth.sql.gz

#put the names of the databases you want to create an individual backup below

$PGBIN/pg_dump -i -p5432  -h $PGHOST -U $PGUSER DB1 | gzip > $BACKUPDIR/DB1-$thedate.sql.gz
$PGBIN/pg_dump -i -p5432  -h $PGHOST -U $PGUSER DB1Snapshot | gzip > $BACKUPDIR/DB1Snapshot-$thedate.sql.gz

#this section deletes the previous month of same day backup except for the full server backup
rm -f $BACKUPDIR/*`date --date="last month" +%Y%m%d`*.sql.gz
pg_dump has options
-w
or
--no-password

    Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be used in batch jobs and scripts where no user is present
I tried to run them in job but it failed which I think due to password requirement, how do I run it in job without pg_dump ask for password ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks....it help me at least....