Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following sections contain examples of how to perform this procedure, and how to perform a restore, when using an Oracle database.

Example of Online Backup of Database and File System

The database part of the backup is made as one full backup and a number of incremental changes. For every incremental backup of the database, a full backup has to be taken of the file system. It is vital to keep file system and Oracle-backups in a consistent state with each other.

Taking a file system snapshot is exemplified with the fssnap utility. Taking database backup, is exemplified using the Oracle RMAN utility.

Note
titleNote!

The instructions presented here are samples used with and Oracle running on a single machine.

Always consult an Oracle Database Administrator when setting up database backup scripts.

  1. Before taking backups, Oracle needs to be set in Archive mode. Make sure the following entries in the initMZ.ora file are present and correct according to the ORACLE installation:

    Code Block
    languagetext
    themeEclipse
    log_archive_dest = /path_to_oracle/redologs_directory 
    log_archive_format = "log_%d_%a_%T_%S_%r.arc"

     

  2. Make a secure backup of initMZ.ora.
      

  3. Run the following commands:

    Code Block
    languagetext
    themeEclipse
    $ sqlplus "/AS SYSDBA" 
    SQL> shutdown <Note, the shutdown must be graceful> 
    SQL> startup mount 
    SQL> alter database archivelog; 
    SQL> archive log start; 
    SQL> alter database open; SQL> quit;

     

  4. Use the following instructions to find the DBID (Database Identifier) and write it down. It is needed if a recovery is to be performed.

    Code Block
    languagetext
    themeEclipse
    $ rman nocatalog 
    RMAN> connect target 
    RMAN-06005: connected to target database: MZ (DBID=749276174) 
    RMAN> exit;

     

  5. Make a full database backup, using a script such as the following:

    Code Block
    languagetext
    themeEclipse
    #! /bin/sh 
    # 
    # Full backup of Oracle tablespaces 
    # 
    # Please note that this script does not save the state of 
    # <product> 
    filesystem. To ensure you got everything backedup,
    # please run the incremental backup script after this script 
    # has finished. 
    # 
    # -------------------------------------------------------------- 
    # 
    Start of Configuration Parameters 
    # -------------------------------------------------------------- 
    # 
    # BACKUP_DIR: Where to store the backup. 
    # 
    BACKUP_DIR=/opt/snap/backup 
    # 
    # CONNECT_STR: Database connection string 
    # 
    CONNECT_STR=backup/backup@MZ 
    # 
    # ------------------------------------------------------------- 
    # 
    End of Configuration Parameters 
    # ------------------------------------------------------------- 
    # Do not change anything after this line. 
    # 
    CURRENT_DATE=`date '+%mm%dd%yy%Hh%Mm%Ss'`; 
    BACKUP_DIR_CURRENT=$BACKUP_DIR/current 
    BACKUP_DIR_SAVED=$BACKUP_DIR/$CURRENT_DATE 
    BACKUP_CONTROL=control.$CURRENT_DATE 
    export BACKUP_DIR_CURRENT CONNECT_STR 
    mv $BACKUP_DIR_CURRENT $BACKUP_DIR_SAVED 
    mkdir $BACKUP_DIR_CURRENT 
    cat <<EOF | $ORACLE_HOME/bin/rman nocatalog 
    connect target $CONNECT_STR; 
    run { 
    # 
    # Allocate backup channel 
    # 
    allocate channel DatabaseBackup type disk format 
    '$BACKUP_DIR_CURRENT/%U'; 
    # 
    # Take a backup of all tablespaces 
    # 
    backup database; 
    # 
    # Tell oracle to switch logfile 
    # 
    sql "alter system switch logfile"; 
    # 
    # We do not really need to backup this controlfile at this 
    # state but it will block until the log switch has occurred. 
    # 
    backup current controlfile; 
    # 
    # Backup archived logfiles 
    # 
    backup archivelog all delete input; 
    } 
    exit; 
    EOF

     

  6. Make an incremental database backup and a file system snapshot. This creates a timestamp backup, to be used for recovery.

    Code Block
    languagetext
    themeEclipse
    #! /bin/sh 
    # 
    # Incremental backup of Oracle and full <product> 
    # Filesystem Snap. 
    # 
    # This scripts saves newly created archivelogs from oracle and 
    # the current state of the <product> 
    filesystem. 
    # 
    # -------------------------------------------------------------- 
    # 
    Start of Configuration Parameters 
    # -------------------------------------------------------------- 
    # 
    # BACKUP_DIR: Where to store the backup. 
    # 
    BACKUP_DIR=/opt/snap/backup 
    # 
    # CONNECT_STR: Database connection string 
    # 
    CONNECT_STR=backup/backup@MZ 
    # 
    # ------------------------------------------------------------- 
    # 
    End of Configuration Parameters 
    # ------------------------------------------------------------- 
    # 
    CURRENT_DATE=`date '+%mm%dd%yy%Hh%Mm%Ss'`; 
    BACKUP_DIR_CURRENT=$BACKUP_DIR/current; 
    BACKUP_DIR_CURRENT_MZFS=$BACKUP_DIR_CURRENT/MZFS_$CURRENT_DATE 
    BACKUP_CONTROL=control.$CURRENT_DATE 
    # 
    # ------------------------------------------------------------- 
    # 
    Start of Configuration Parameters 
    # ------------------------------------------------------------- 
    # 
    # SNAP_COMMAND: Command to execute to create the filesystem snap. 
    # 
    SNAP_COMMAND="fssnap -Fufs -omaxsize=500m, 
    bs=/opt/snap,unlink /export/home" 
    # 
    # SNAP_MOUNT: Command to mount the filesystem snapshot. 
    # 
    SNAP_MOUNT="mount -Fufs -o ro /dev/fssnap/0 /opt/snap/mount" 
    # 
    # SNAP_BACKUP: Command to backup the snapshot while its mounted. 
    # 
    SNAP_BACKUP="cp -Rp /opt/snap/mount $BACKUP_DIR_CURRENT_MZFS"; 
    # 
    # SNAP_UNMOUNT: Command to unmount the snapshot. 
    # 
    SNAP_UNMOUNT="umount /opt/snap/mount" 
    # 
    # ------------------------------------------------------------- 
    # 
    End of Configuration Parameters 
    # -------------------------------------------------------------
    # Do not change anything after this line. 
    # 
    mkdir $BACKUP_DIR_CURRENT_MZFS; 
    export BACKUP_DIR_CURRENT BACKUP_CONTROL CONNECT_STR 
    export SNAP_COMMAND SNAP_MOUNT SNAP_BACKUP SNAP_UNMOUNT 
    # 
    cat <<EOF | $ORACLE_HOME/bin/rman nocatalog 
    connect target $CONNECT_STR 
    run { 
    allocate channel DatabaseBackup type disk format 
    '$BACKUP_DIR_CURRENT/%U'; 
    # 
    # 1) Backup and remove all old redologs. 
    # 
    sql "alter system switch logfile"; 
    backup current controlfile; 
    backup archivelog all delete input; 
    # 
    # 2) Lock transaction table. 
    # 3) Take a FileSystem Snapshot. 
    # 4) Backup new and active redologs. 
    # 5) Unlock transaction table. 
    # 
    sql "lock table mzadmin.wf_txn in exclusive mode"; 
    sql "alter system switch logfile"; 
    host "$SNAP_COMMAND"; 
    backup current controlfile; 
    backup archivelog all delete input; 
    sql "alter database backup controlfile to 
    ''$BACKUP_DIR_CURRENT/$BACKUP_CONTROL'' reuse"; 
    sql "commit"; 
    host "$SNAP_MOUNT"; 
    host "$SNAP_BACKUP"; 
    host "$SNAP_UNMOUNT"; 
    } 
    exit; 
    EOF


Example of Restoring an Online Backup

In case of critical failure, the system may be recovered with the backup files produced using a procedure such as the example described in the previous section.

...