Forum OpenACS Q&A: shut down postgreSQL server remotely

I want to run backup and auto restore from a script, that will take the backup of the database from a remote host and restore it. I can take backup, now the problem is restoring, before restoring I have to drop the database, but i can't drop the database if any client is connected to it, I want to close the connection or shut down the server remotely so that then I can restore easily..please can anyone help me?
Collapse
Posted by Steve Manning on
Syed

This is the script which I use to do the same thing but with  the aolserver under the control of daemontools and the two systems synced using rsync.

I also dump the database schema and data separately as I find I can restore without errors by splitting them.

===================

#!/bin/sh
#
# OpenACS Daemontools Shutdown Script
#
#

{

echo -n "===== Started "
date

# Kill the current nsd
/usr/local/bin/svc -d /service/foobar

# RSync the systems
su -c '/usr/bin/rsync --recursive --links --perms --times --checksum --compress --verbose --delete \
    -e ssh "mailto:auser@www.foobar.com:/var/lib/aolserver/foobar" \
    --exclude="foobar/etc/*" /var/lib/aolserver ' nsadmin

echo -n "===== Restore DB "
date

# Update the database
su -c '/usr/bin/dropdb foobar' nsadmin
su -c '/usr/bin/createdb --template=template0 --encoding=UNICODE foobar' nsadmin
su -c '/usr/bin/psql foobar < /var/lib/aolserver/foobar/database-backup/foobar_schema.dmp' nsadmin
su -c '/usr/bin/psql foobar < /var/lib/aolserver/foobar/database-backup/foobar_data.dmp' nsadmin

# Restart NSD
/usr/local/bin/svc -u /service/foobar

echo -n "===== Completed "
date

} > /var/lib/aolserver/foobar/etc/sync_live.log 2>&1

=======================

  - Steve

Collapse
Posted by Jade Rubick on
Here's another script, one you can put in your crontab:

/usr/local/bin/svc -d /service/ibr
/bin/sleep 60
/usr/local/pgsql/bin/dropdb ibr
/usr/local/pgsql/bin/createdb -E UNICODE ibr
/usr/local/pgsql/bin/psql -f /home/ibr/8000/packages/acs-kernel/sql/postgresql/postgresql.sql ibr
mv /home/ibr/8000/database-backup/ibr-nightly-backup.dmp /home/ibr/8000/database-backup/ibr-nightly-backup-old.dmp
/bin/gunzip /home/ibr/8000/database-backup/ibr-nightly-backup.dmp.gz
/usr/local/pgsql/bin/psql ibr < /home/ibr/8000/database-backup/ibr-nightly-backup.dmp
/usr/local/bin/svc -u /service/ibr
/bin/gzip /home/ibr/8000/database-backup/ibr-nightly-backup-old.dmp