daily pastebin goal
78%
SHARE
TWEET

RHN hot-backup.sh

trishoar Mar 4th, 2013 17 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. # This script performs a hot backup of an embedded RHN Oracle database. It takes
  4. # a single argument which is either 'full' or 'incremental' which determines
  5. # what kind of backup will be performed. An incremental backup is incremental to
  6. # the most recent full backup.
  7.  
  8. # The script cleans up the catalog in the db control file if files are deleted
  9. # from the disk outside of rman.
  10.  
  11. # The script also deletes obsolete archive logs and backups. The retention
  12. # policy for configuring this was set in the prep script.
  13.  
  14. # Matthew Booth <mbooth@redhat.com> 22/09/2006
  15.  
  16. function errormsg() {
  17.         echo $* > /dev/stderr
  18. }
  19.  
  20. # Make sure we're root
  21. # Could just be Oracle, but root is simpler for administrators
  22. if [ `id -u` -ne 0 ]; then
  23.     errormsg This script must be executed as root
  24.     exit 1
  25. fi
  26.  
  27. # Check whether this is a full or incremental backup
  28. case $1 in
  29.         full)
  30.                 inc_level=0
  31.                 ;;
  32.         incremental)
  33.                 inc_level=1
  34.                 ;;
  35.        
  36.         *)
  37.                 errormsg Usage: $0 '(full|incremental)'
  38.                 exit 1
  39.                 ;;
  40. esac
  41.  
  42. # Check the rhn database is running
  43. if ! /sbin/service rhn-database status > /dev/null; then
  44.         errormsg The rhn-database service must be running to perform a hot backup
  45.         exit 1
  46. fi
  47.  
  48. # Become the oracle user
  49. su - oracle -c "/bin/bash -s $1 $inc_level" <<-'ORACLE' >> /var/log/rhn/db_backup.log
  50.         export ORACLE_SID=rhnsat
  51.         inc_label=$1
  52.         inc_level=$2
  53.  
  54.         echo ===================================================================
  55.         echo Starting $inc_label backup at `date`
  56.         echo ===================================================================
  57.  
  58.         # Check for archivelogs and backups which were manually deleted from disk
  59.         # Remove manually deleted archivelogs and backups from the catalog
  60.         # Perform an rman backup
  61.         # Remove backups and archivelogs which are not required by the retention
  62.         # policy
  63.         rman target / nocatalog <<-EOF
  64.                 crosscheck archivelog all;
  65.                 crosscheck backup;
  66.  
  67.                 delete noprompt expired archivelog all;
  68.                 delete noprompt expired backup;
  69.  
  70.                 run {
  71.                         allocate channel d1 device type disk
  72.                                 format '/rhnsat/backup/data/%U';
  73.  
  74.                         backup incremental level = $inc_level database
  75.                                 include current controlfile plus archivelog delete all input;
  76.                 }
  77.  
  78.                 delete noprompt obsolete;
  79.         EOF
  80.  
  81.         # Verify that the backup is valid
  82.         nvalid=`rman target / nocatalog <<-EOF | grep "^Finished restore" | wc -l
  83.                 restore database validate;
  84.                 restore controlfile to '/tmp/rhndb-cf' validate;
  85.                 restore spfile to '/tmp/rhndb-spfile' validate;
  86.         EOF
  87.         `
  88.  
  89.         # If we couldn't validate database, controlfile and spfile, write an error
  90.         # message to stderr
  91.         if [ $nvalid -ne 3 ]; then
  92.                 echo "DATABASE BACKUP IS INVALID!"
  93.                 echo
  94.                 exit 1
  95.         else
  96.                 echo "Backup is valid"
  97.                 echo
  98.         fi
  99. ORACLE
  100.  
  101. if [ $? -ne 0 ]; then
  102.         errormsg An error occurred while backing up the database. Check /var/log/rhn/db_backup.log for details.
  103.         exit 1
  104. fi
  105.  
  106. # vim: ts=4 sw=4 smartindent noexpandtab
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top