motioneye
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/f ullbackup- 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/PostgresPl us/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-$the month.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.co mpressed $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
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/f
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/PostgresPl
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-$the
#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.co
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/PostgresPl us/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-$the month.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.sq l.gz
$PGBIN/pg_dump -i -p5432 -h $PGHOST -U $PGUSER DB1Snapshot | gzip > $BACKUPDIR/DB1Snapshot-$th edate.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
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/PostgresPl
PGHOST="localhost"
PGUSER="postgres"
PGBIN="/opt/PostgresPlus/9
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-$the
#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.sq
$PGBIN/pg_dump -i -p5432 -h $PGHOST -U $PGUSER DB1Snapshot | gzip > $BACKUPDIR/DB1Snapshot-$th
#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
-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
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks....it help me at least....
Issue command
Open in new window
Also
Open in new window
Show the results