<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Backup and Recovery</title><meta name="generator" content="DocBook XSL Stylesheets V1.50.0"><link rel="home" href="index.html" title="OpenACS Documentation"><link rel="up" href="maintenance.html" title="Chapter 7. Maintenance"><link rel="previous" href="database-management.html" title="Database Management"><link rel="next" href="install-redhat.html" title="Appendix A. Install Red Hat 8.0"><link rel="stylesheet" href="openacs.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><a href="http://openacs.org"><img src="images/alex.jpg" border="0"></a><table width="100%" summary="Navigation header" border="0"><tr><td width="20%" align="left"><a accesskey="p" href="database-management.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter 7. Maintenance</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="install-redhat.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="backup-recovery"></a>Backup and Recovery</h2></div></div><div class="authorblurb"><p>
    by <a href="mailto:dhogaza@pacifier.com" target="_top">Don Baccus</a>
      with additions by <a href="mailto:joel@aufrecht.org" target="_top">Joel Aufrecht</a><br>
          OpenACS docs are written by the named authors, but may be edited
          by OpenACS documentation staff.
        </p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="install-next-backups"></a>Backup Strategy</h3></div></div><p>
      The purpose of backup is to enable recovery.  Backup and
      recovery are always risky; here are some steps that minimize the
      chance recovery is necessary:
    </p><div class="itemizedlist"><ul type="disc"><li><p>
          Store everything on a fault-tolerant disk array (RAID 1 or 5
          or better).
        </p></li><li><p>
          Use battery backup.
        </p></li><li><p>
          Use more reliable hardware, such as SCSI instead of IDE.
        </p></li></ul></div><p>These steps improve the chances of successful recovery:</p><div class="itemizedlist"><ul type="disc"><li><p>
          Store backups on a third disk on another controller
        </p></li><li><p>
          Store backups on a different computer on a different network
          in a different physical location.  (Compared to off-line
          backup such as tapes and CDRs, on-line backup is faster and
          more likely to succeed, but requires maintenance of another machine.)
        </p></li><li><p>
          Plan and configure for recovery from the beginning.
        </p></li><li><p>
          Test your recovery strategy from time to time.
        </p></li><li><p>
          Make it easy to maintain and test your recovery strategy, so
          that you are more likely to do it.
        </p></li></ul></div><p>
        OpenACS installations comprise files and database contents.
        If you follow the reference install and put all files,
        including configuration files, in
        <tt>/web/<span class="replaceable">servicename</span>/</tt>,
        and back up the database nightly to a file in
        <tt>/web/<span class="replaceable">servicename</span>/database-backup</tt>,
        then you can apply standard file-based backup strategies to the root
        directory.
</p></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="postgres-quick-backup"></a>Set up Nightly Postgres Exports</h3></div></div><p>A quick way to automate database backup is a cron job.
      (This should moved into OpenACS's scheduled task project so that
      it's integrated with OpenACS's alerts and such.)</p><pre class="screen">[service0@yourserver service0]$ export EDITOR=emacs;crontab -e</pre><p>Add this line to the file.  The numbers and stars at the beginning are cron columns that specify when the program should be run - in this case, whenever the minute is 0 and the hour is 1, i.e., 1:00 am every day.</p><pre class="programlisting">0 1 * * * /usr/local/pgsql/bin/pg_dump -f /web/<span class="replaceable">service0</span>/database-backup/<span class="replaceable">service0</span>_$(date +%Y-%m-%d).dmp <span class="replaceable">service0</span></pre></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="backup-file-system"></a>Back up the file system</h3></div></div><p>Here's a quick manual way to back up a reference install -
      it should be replaced by an automated script within
      OpenACS.  The command excludes the auto-generated
      <tt>supervise</tt> directory, which is
      unneccesary and has complicated permissions.  Make sure that you are using the cron job to back up the database to a file in <tt>/web/<span class="replaceable">service0</span>/database-backup</tt> so that the tar command will include the database.</p><pre class="screen">[root@yourserver root]# <b><tt>su - <span class="replaceable">service0</span></tt></b>
[service0@yourserver service0]$ <b><tt>tar -cpsj --exclude /web/<span class="replaceable">service0</span>/etc/daemontools/supervise --file /tmp/<span class="replaceable">service0</span>-backup.tar.bz2 /web/<span class="replaceable">service0</span>/ --exclude /web/<span class="replaceable">service0</span>/etc/daemontools/supervise/</tt></b>
tar: Removing leading `/' from member names
[service0@yourserver service0]$</pre></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="id2850480"></a>Testing</h3></div></div><p><span class="emphasis"><em>On a test service</em></span>, make sure that your backup-recovery process work.  After backing up the database and file system, delete the service as detailed below and then recover it.</p><pre class="screen">[root@yourserver root]# <b><tt>svc -d /service/service0</tt></b>
[root@yourserver root]# <b><tt>mv /web/service0/ /web/service0.lost</tt></b>
[root@yourserver root]#<b><tt> rm /service/service0</tt></b>
rm: remove symbolic link `/service/service0'? y
[root@yourserver root]# <b><tt>ps -auxw | grep service0</tt></b>
root      1496  0.0  0.0  1312  252 ?        S    16:58   0:00 supervise service0
[root@yourserver root]#<b><tt> kill<span class="replaceable"> 1496</span></tt></b>
[root@yourserver root]# <b><tt>ps -auxw | grep service0</tt></b>
[root@yourserver root]# <b><tt>su - postgres</tt></b>
[postgres@yourserver pgsql]$ <b><tt>dropdb service0</tt></b>
DROP DATABASE
[postgres@yourserver pgsql]$ <b><tt>dropuser service0</tt></b>
DROP USER
[postgres@yourserver pgsql]$ <b><tt>exit</tt></b>
logout
[root@yourserver root]#</pre></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="Recovery"></a>Recovery</h3></div></div><div class="orderedlist"><ol type="1"><li><p>Restore the operating system and required software.
          You can do this with standard backup processes or by
          keeping copies of the install material (OS CDs, OpenACS
          tarball and supporting software) and repeating the install guide.</p></li><li><p>Restore the OpenACS service.  Assuming the user already exists, restore the database and files from backup and restore the daemontools link.  (Because of a bug in Postgres backup-recovery, not all database objects are created in the correct order.  To compensate, pre-creating some objects usually work.)</p><pre class="screen">[root@yourserver root]# <b><tt>su - postgres</tt></b>
[postgres@yourserver pgsql]$ <b><tt>createuser <span class="replaceable">service0</span></tt></b>
Shall the new user be allowed to create databases? (y/n) <b><tt>y</tt></b>
Shall the new user be allowed to create more new users? (y/n) <b><tt>y</tt></b>
CREATE USER
[postgres@yourserver pgsql]$ <b><tt>exit</tt></b>
logout

[root@yourserver root]# <b><tt>su - <span class="replaceable">service0</span></tt></b>
[service0@yourserver service0]$ <b><tt>cd /web</tt></b>
[service0@yourserver web]$<b><tt> tar xjf /tmp/service0-backup.tar.bz2</tt></b>
[service0@yourserver web]$ <b><tt>chmod -R 700 service0</tt></b>
[service0@yourserver web]$ <b><tt>createdb <span class="replaceable">service0</span></tt></b>
CREATE DATABASE
[service0@yourserver web]$<b><tt> psql -f /web/<span class="replaceable">service0</span>/packages/acs-kernel/sql/postgresql/postgresql.sql <span class="replaceable">service0</span></tt></b>
<span class="emphasis"><em>(many lines omitted)</em></span>
[service0@yourserver web]$ <b><tt>psql <span class="replaceable">service0</span> &lt; /web/<span class="replaceable">service0</span>/database-backup/<span class="replaceable">database-backup.dmp</span></tt></b>
<span class="emphasis"><em>(many lines omitted)</em></span>
[service0@yourserver web]$ <b><tt>exit</tt></b>
[root@yourserver root]# <b><tt>ln -s /web/<span class="replaceable">service0</span>/etc/daemontools /service/<span class="replaceable">service0</span></tt></b>
[root@yourserver root]# <b><tt>sleep 10</tt></b>
[root@yourserver root]# <b><tt>svgroup web /service/<span class="replaceable">service0</span></tt></b>
[root@yourserver root]#</pre></li></ol></div></div><div class="sect2"><div class="titlepage"><div><h3 class="title"><a name="other-backup-strategies"></a>Other Backup Strategies</h3></div></div><p>Earlier strategies, included here because this section
        hasn't been fully updated yet.</p><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="install-export-oracle"></a>Set Up Nightly Oracle Exports</h4></div></div><p>
      (This has not yet been updated to fit with the Reference
      install.  To do so, edit the backup script to save the backup
      file in <tt>/web/<span class="replaceable">servicename</span>/database-backup</tt>).
      While you're working with Oracle, you should configure it to do
      automatic exports. An export is a separate backup copy of the
      database.  This copy includes all of the database's state at the
      time that the export was initiated. If your database is corrupted,
      you can restore from one of these backups. You should do this step as
      <tt>root</tt>.
    </p><div class="itemizedlist"><ul type="disc"><li><p> 
          Download the backup script. Save the file <a href="files/export-oracle.txt" target="_top">export-oracle.txt</a> as
          <tt>/tmp/export-oracle.txt</tt>
        </p></li><li><p>
          Login as root. The following commands will install the export script:
        </p><pre class="programlisting">
joeuser:~$ su -
Password: ***********
root:~# cp /tmp/export-oracle.txt /usr/sbin/export-oracle
root:~# chmod 700 /usr/sbin/export-oracle</pre></li><li><p>
        Setup the export directory; this is the directory where backups will
        be stored. We recommend the directory
        <tt>/ora8/m02/oracle-exports</tt>.</p><pre class="programlisting">
root:~# mkdir /ora8/m02/oracle-exports
root:~# chown oracle.dba /ora8/m02/oracle-exports
root:~# chmod 770 /ora8/m02/oracle-exports</pre></li><li><p> 
          Now edit
          <tt>/usr/sbin/export-oracle</tt> and
          change the <tt>SERVICE_NAME</tt> and
          <tt>DATABASE_PASSWORD</tt> fields to
          their correct values. If you want to use a directory other than
          <tt>/ora8/m02/oracle-exports</tt>, you
          also need to change the
          <tt>exportdir</tt> setting.
        </p><p>
          Test the export procedure by running the command:
        </p><pre class="programlisting">
root:~# /usr/sbin/export-oracle
mv: /ora8/m02/oracle-exports/oraexport-service_name.dmp.gz: No such file or directory

Export: Release 8.1.6.1.0 - Production on Sun Jun 11 18:07:45 2000

(c) Copyright 1999 Oracle Corporation.  All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
Export done in US7ASCII character set and US7ASCII NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SERVICE_NAME 
. exporting object type definitions for user SERVICE_NAME 
About to export SERVICE_NAME's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SERVICE_NAME's tables via Conventional Path ...
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting snapshots
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.</pre><p>If you don't have any warnings, proceed to automate the
          backups.</p></li><li><p>
          Automating backups is accomplished using the UNIX
          <tt>crontab</tt> facility.</p><p>
          While still <tt>root</tt>, run the
          following command. You can replace the
          <tt>EDITOR=&quot;emacs -nw&quot;</tt>
          portion with whatever editor your prefer, such as
          <tt>EDITOR=vi</tt>.
        </p><pre class="programlisting">
root:~# export EDITOR=&quot;emacs -nw&quot;
root:~# crontab -e</pre><p>Now add the following line on a line by itself </p><pre class="programlisting">
0 23 * * * /usr/sbin/export-oracle</pre><p>
          Save the file, exit the editor. Verify that the addition
          succeeded by checking the output of the following command.</p><pre class="programlisting">
root:~# crontab -l | grep export-oracle
0 23 * * * /usr/sbin/export-oracle
root:~# exit
; Logout</pre><p>If you see the line, go ahead and log out.</p></li></ul></div></div><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="install-export-postgres"></a>Set up nightly Postgres exports</h4></div></div><p>
      (This is not required for the Reference install.)
      Dowload <a href="files/acs-pgbackup-init.txt" target="_top">this script</a>
      to <tt>/tmp</tt>. At the top of the script
      are several variables that you'll need to customize:
    </p><div class="itemizedlist"><ul type="disc"><li><p>
          <tt>bak</tt> - location where you want
          local backups to be saved
        </p></li><li><p>
          <tt>servername</tt> - name of your server
          (and database instance)
        </p></li><li><p>
          <tt>ftp_user</tt> - username on your ftp
          account 
        </p></li><li><p>
          <tt>ftp_password</tt> - password on your
          ftp account
        </p></li><li><p>
          <tt>ftp_dir</tt> - path on the remote
          server where your backups will be uploaded
        </p></li><li><p>
          <tt>ftp_server</tt> - your ftp server
        </p></li></ul></div><p>

      Next, we'll save this file to our server's
      <tt>tcl</tt> directory so that it will be
      loaded on startup. It will automatically be run every night at
      midnight. Note that this script only backs up the database - not the
      OpenACS scripts and file content.
    </p><pre class="programlisting">
joeuser:~$ cp /tmp/acs-pgbackup-init.txt ~/web/birdnotes/tcl/acs-pgbackup-init.tcl
joeuser:~$ restart-aolserver birdnotes</pre><p>
      That's it! The script will email you with each successful backup (or
      if it fails, it will send you an email with the reason)
    </p></div></div><p><div class="cvstag">($Id: backup-recovery.html,v 1.1.2.2 2003/03/30 06:04:04 joela Exp $)</div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="database-management.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="install-redhat.html">Next</a></td></tr><tr><td width="40%" align="left">Database Management&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="maintenance.html">Up</a></td><td width="40%" align="right">&nbsp;Appendix A. Install Red Hat 8.0</td></tr></table><hr><address>rmello at fslc.usu.edu</address><address><a href="mailto:vinod@kurup.com">vinod@kurup.com</a></address></div><a name="comments"></a><center><a href="http://openacs.org/doc/openacs-4/backup-recovery.html#comments">View comments on this page at openacs.org</a></center></body></html>