Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This script performs a hot backup of an embedded RHN Oracle database. It takes
- # a single argument which is either 'full' or 'incremental' which determines
- # what kind of backup will be performed. An incremental backup is incremental to
- # the most recent full backup.
- # The script cleans up the catalog in the db control file if files are deleted
- # from the disk outside of rman.
- # The script also deletes obsolete archive logs and backups. The retention
- # policy for configuring this was set in the prep script.
- # Matthew Booth <mbooth@redhat.com> 22/09/2006
- function errormsg() {
- echo $* > /dev/stderr
- }
- # Make sure we're root
- # Could just be Oracle, but root is simpler for administrators
- if [ `id -u` -ne 0 ]; then
- errormsg This script must be executed as root
- exit 1
- fi
- # Check whether this is a full or incremental backup
- case $1 in
- full)
- inc_level=0
- ;;
- incremental)
- inc_level=1
- ;;
- *)
- errormsg Usage: $0 '(full|incremental)'
- exit 1
- ;;
- esac
- # Check the rhn database is running
- if ! /sbin/service rhn-database status > /dev/null; then
- errormsg The rhn-database service must be running to perform a hot backup
- exit 1
- fi
- # Become the oracle user
- su - oracle -c "/bin/bash -s $1 $inc_level" <<-'ORACLE' >> /var/log/rhn/db_backup.log
- export ORACLE_SID=rhnsat
- inc_label=$1
- inc_level=$2
- echo ===================================================================
- echo Starting $inc_label backup at `date`
- echo ===================================================================
- # Check for archivelogs and backups which were manually deleted from disk
- # Remove manually deleted archivelogs and backups from the catalog
- # Perform an rman backup
- # Remove backups and archivelogs which are not required by the retention
- # policy
- rman target / nocatalog <<-EOF
- crosscheck archivelog all;
- crosscheck backup;
- delete noprompt expired archivelog all;
- delete noprompt expired backup;
- run {
- allocate channel d1 device type disk
- format '/rhnsat/backup/data/%U';
- backup incremental level = $inc_level database
- include current controlfile plus archivelog delete all input;
- }
- delete noprompt obsolete;
- EOF
- # Verify that the backup is valid
- nvalid=`rman target / nocatalog <<-EOF | grep "^Finished restore" | wc -l
- restore database validate;
- restore controlfile to '/tmp/rhndb-cf' validate;
- restore spfile to '/tmp/rhndb-spfile' validate;
- EOF
- `
- # If we couldn't validate database, controlfile and spfile, write an error
- # message to stderr
- if [ $nvalid -ne 3 ]; then
- echo "DATABASE BACKUP IS INVALID!"
- echo
- exit 1
- else
- echo "Backup is valid"
- echo
- fi
- ORACLE
- if [ $? -ne 0 ]; then
- errormsg An error occurred while backing up the database. Check /var/log/rhn/db_backup.log for details.
- exit 1
- fi
- # vim: ts=4 sw=4 smartindent noexpandtab
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement