Skip to content

Instantly share code, notes, and snippets.

@patrickkeller
Created November 6, 2012 11:20
Show Gist options
  • Save patrickkeller/4024120 to your computer and use it in GitHub Desktop.
Save patrickkeller/4024120 to your computer and use it in GitHub Desktop.
Avaya ACR Postgres Set-Up-Backup-Script
#!/bin/bash
# add new user to the system. the backups will be saved in the home dir
userdel backup
useradd -g users -u 1003 -m -s /bin/bash backup
passwd backup # ask for password
echo "User backup with defined password sucessfully added"
###
# writes the backupscript to pg_dump_cron.sh
cat <<EOF > /var/lib/pgsql/pg_dump_cron.sh
#!/bin/bash
echo "Job started:"
date
pg_dump --format=c --compress=9 eware > postgres_backup.bac
chmod 640 postgres_backup.bac
chown backup postgres_backup.bac
chgrp users postgres_backup.bac
mv postgres_backup.bac /home/backup/postgres_backup.bac
echo "Job finished:"
date
echo "Backup saved to /home/backup/postgres_backup.bac"
echo "#################################################"
EOF
chmod u+x /var/lib/pgsql/pg_dump_cron.sh
# add script to crontab
tmp=${TMPDIR:-/tmp}/xyz.$$
trap "rm -f $tmp; exit 1" 0 1 2 3 13 15
crontab -l | sed '/var/lib/pgsql/pg_dump_cron.sh/d' > $tmp # Capture crontab; delete old entry
echo "0 0 * * 1-5 /var/lib/pgsql/pg_dump_cron.sh >> /var/lib/pgsql/pg_dump_cron.log" >> $tmp
crontab < $tmp
rm -f $tmp
trap 0
echo "Backup-Script (/var/lib/pgsql/pg_dump_cron.sh) sucessfully added to crontab."
echo "Type 'crontab -l' to review"
service crond restart # restart crond, just to be sure...
@patrickkeller
Copy link
Author

  1. Login as root
  2. Copy Script to your ACR Server (save the script under 'script.sh')
  3. Change execution permission with 'chmod u+x script.sh'
  4. Run script with './script.sh'. Done!

@patrickkeller
Copy link
Author

You can fetch the backups with the "backup" User. The backups are located under /home/backup

@mosama77
Copy link

Hi Patrick,

I tried the script but it creates the file with 0 size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment