Created
November 6, 2012 11:20
-
-
Save patrickkeller/4024120 to your computer and use it in GitHub Desktop.
Avaya ACR Postgres Set-Up-Backup-Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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... |
Author
patrickkeller
commented
Nov 6, 2012
- Login as root
- Copy Script to your ACR Server (save the script under 'script.sh')
- Change execution permission with 'chmod u+x script.sh'
- Run script with './script.sh'. Done!
You can fetch the backups with the "backup" User. The backups are located under /home/backup
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