...
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 | ||
---|---|---|
| ||
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. |
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 language text theme Eclipse log_archive_dest = /path_to_oracle/redologs_directory log_archive_format = "log_%d_%a_%T_%S_%r.arc"
Make a secure backup of
initMZ.ora
.
Run the following commands:
Code Block language text theme Eclipse $ 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;
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 language text theme Eclipse $ rman nocatalog RMAN> connect target RMAN-06005: connected to target database: MZ (DBID=749276174) RMAN> exit;
Make a full database backup, using a script such as the following:
Code Block language text theme Eclipse #! /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
Make an incremental database backup and a file system snapshot. This creates a timestamp backup, to be used for recovery.
Code Block language text theme Eclipse #! /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
...
Note | ||
---|---|---|
| ||
|
Shut down
.
Shut down the Oracle Instance.
Make a cold backup of the crashed crashed , including the Oracle instance.
Locate the backup to restore. That is, a directory containing a full backup and at least one incremental backup. The directory should contain one or several Oracle control files
control.<id>,
and and a snapshot of the file systemMZFS_<id>
.
Remove all table space files, the corresponding archived redo logs, and control files. If necessary, remove the
initMZ.ora
file as well, and replace it with the backed up version.
Make a backup copy of the control files
MZ_control1
andMZ_control2
.
Replace the dynamic directories with the corresponding backup directories. An example of a dynamic directory is the storage handler directory, used by the Inter Workflow application.
Execute the following commands:
Code Block language text theme Eclipse $ export BACKUP_DIR=/path_to_backup_to_use $ rman nocatalog RMAN> set dbid = <DBID> RMAN> connect target; RMAN> startup force mount; RMAN> run { RMAN> allocate channel SystemRestore type disk format '$BACKUP_DIR/%U'; RMAN> restore database; RMAN> restore archivelog all; RMAN> } The reply messages are: RMAN-08017: RMAN-08022: RMAN-08510: RMAN-08023: RMAN-08511: RMAN-08024: RMAN-08031: channel SystemRestore: starting archivelog... channel SystemRestore: restoring archivelog archivelog thread=1 sequence=20 channel SystemRestore: restore backup... piece handle=/tmp/backup/0feduv7h_1_1... channel SystemRestore: restore complete released channel: SystemRestore Use the last RMAN-08510 to fill in 'set until logseq NR thread NR' RMAN> run { RMAN> allocate channel SystemRestore type disk format 'BACKUP_DIR/%U'; RMAN> set until logseq 20 thread 1; RMAN> recover database; RMAN> alter database open resetlogs; RMAN>} RMAN> exit;
Restart the database instance with the following commands:
Code Block language text theme Eclipse SQL> shutdown normal SQL> startup
Start
.