This guide will prepare you to run a simple RMAN shell script to perform a hot backup of the full database. In addition, you will learn few useful commands on how to list the RMAN binary backup files and on how to crosscheck if the backed up files are physically present on disk. |
- A sample RMAN shell script
- Explain the script
- A snapshot of RMAN backup location
- Listing the backup/backupsets
- Crosschecking the backup/backupsets
|
|
1. A sample RMAN shell script |
|
Following is a simple RMAN shell script to backup full database including archivelogs using one day retention. |
|
# --- rman_bkp_dbuat01.sh --- #
date;
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=dbuat01
$ORACLE_HOME/bin/rman nocatalog <<EOF
connect target /
run {
delete noprompt obsolete redundancy 1;
configure backup optimization on;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u02/oradata/backup/dbuat01/rman/dbuat01_%F';
configure snapshot controlfile name to '/u02/oradata/backup/dbuat01/rman/snapcf_dbuat01.f';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
change archivelog all crosscheck;
allocate channel bkp1 device type disk;
allocate channel bkp2 device type disk;
backup as compressed backupset format '/u02/oradata/backup/dbuat01/rman/%d_rman_bkp_%T_%t_%u_%s_%p' database plus archivelog;
backup current controlfile;
sql "alter database backup controlfile to trace as ''/u02/oradata/backup/dbuat01/rman/dbuat01_controlfile_trace.txt'' reuse";
release channel bkp1;
release channel bkp2;
delete noprompt obsolete redundancy 1;
}
exit
EOF
cp -p $ORACLE_HOME/dbs/initdbuat01.ora /u02/oradata/backup/dbuat01/rman/
cp -p $ORACLE_HOME/dbs/spfiledbuat01.ora /u02/oradata/backup/dbuat01/rman/
cp -p $ORACLE_HOME/dbs/orapwdbuat01 /u02/oradata/backup/dbuat01/rman/
cp -p $ORACLE_HOME/network/admin/tnsnames.ora /u02/oradata/backup/dbuat01/rman/
cp -p $ORACLE_HOME/network/admin/listener.ora /u02/oradata/backup/dbuat01/rman/
date; |
|
2. Explain the script |
|
The first few lines of the script on the top are so obvious. Then the commands embraced within the 'run' block are the actual commandline instructions to the target database by RMAN. |
|
- delete noprompt obsolete redundancy 1; - this ensures that the backed up backupsets will be retained on disk for one day. if we set it for 7 days, then it will retain backupsets for 7 days. On the eighth day, when the same script is executed, it will remove the backupsets falling outside the retention window automatically.
- configure controlfile autobackup on; - RMAN will include controlfile backup whenever database backup is performed.
- configure controlfile autobackup format for device type disk to '/u02/oradata/backup/dbuat01/rman/dbuat01_%F'; - redirects the controlfile backup to the desired location. '%F' ensures a unique id generation of the controlfile each time the database structure is modified.
- configure snapshot controlfile name to '/u02/oradata/backup/dbuat01/rman/snapcf_dbuat01.f';" - places the snapshot controlfile in the desired location.
- sql 'alter system archive log current'; - performs few logswitches.
- change archivelog all crosscheck; - checks whether all of the registered archived redo logs are still existing. if not, RMAN marks their status in the controlfile metadata as 'EXPIRED'.
- allocate channel bkp1 device type disk; - tells RMAN to perform backup using channel 'bkp1'.
- allocate channel bkp2 device type disk; - tells RMAN to perform backup using channel 'bkp2'.
- backup as compressed backupset format ... - performs the actual backup (compressed) of the database. %d - for database name {eg. DBUAT01}, %T - for timestamp {20120704}, %t - The backup set timestamp, which is a 4-byte value derived as the number of seconds elapsed since a fixed reference time. The combination of %s and %t can be used to form a unique name for the backup set. %u - an 8-character name constituted by compressed representations of the backupset number. %s - backupset number. %p - backup piece number.
- backup current controlfile; - backs up the controlfile.
- sql "alter database backup controlfile ... - it's always useful to take a controlfile trace.
- allocate channel bkp1 device type disk; - releases channel bkp1
- allocate channel bkp2 device type disk; - releases channel bkp2
- the remaining lines are just copy commands to backup the other important files as part of the RMAN job. it's may be quite handy to do that.
|
|
3. A snapshot of RMAN backup location |
|
The location where the RMAN backup was placed. |
|
[ora11g@rhel5401 rman]$ ls -lrt
total 56028
-rwxrwxr-x 1 ora11g oinstall 617 Jun 15 12:16 initdbuat01.ora
-rw-r--r-- 1 ora11g oinstall 354 Jun 17 12:28 listener.ora
-rw-r--r-- 1 ora11g oinstall 415 Jun 17 12:51 tnsnames.ora
-rw-r----- 1 ora11g oinstall 2048 Jul 3 11:30 orapwdbuat01
-rw-r----- 1 ora11g oinstall 3584 Jul 4 09:04 spfiledbuat01.ora
-rw-r----- 1 ora11g oinstall 1064960 Jul 4 10:19 DBUAT01_rman_bkp_20120704_787745968_3fnf835g_111_1
-rw-r----- 1 ora11g oinstall 36159488 Jul 4 10:19 DBUAT01_rman_bkp_20120704_787745968_3gnf835g_112_1
-rw-r----- 1 ora11g oinstall 2560 Jul 4 10:19 DBUAT01_rman_bkp_20120704_787745975_3hnf835n_113_1
-rw-r----- 1 ora11g oinstall 9977856 Jul 4 10:19 snapcf_dbuat01.f
-rw-r----- 1 ora11g oinstall 10059776 Jul 4 10:19 dbuat01_c-2689589391-20120704-07
-rw-r--r-- 1 ora11g oinstall 7782 Jul 4 10:19 dbuat01_controlfile_trace.txt |
|
|
4. Listing the backup/backupsets |
|
A quick look at the database schema: |
|
RMAN> report schema;
Report of database schema for database with db_unique_name DBUAT01
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 500 SYSTEM *** /u02/oradata/dbuat01/data/tbs_system_01.dbf
2 500 SYSAUX *** /u02/oradata/dbuat01/data/tbs_sysaux_01.dbf
3 500 UNDOTBS01 *** /u02/oradata/dbuat01/data/tbs_undotbs01_01.dbf
4 1024 USERS *** /u02/oradata/dbuat01/data/tbs_users_01.dbf
5 500 ARUN *** /u02/oradata/dbuat01/data/ts_arun_01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 100 TEMPTBS01 100 /u02/oradata/dbuat01/data/tbs_temptbs01_01.dbf |
|
To list backup summary, issue the following command: |
|
RMAN> list backup summary;
using target database control file instead of recovery catalog
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
111 B F A DISK 04-JUL-12 1 1 YES TAG20120704T101928
112 B F A DISK 04-JUL-12 1 1 YES TAG20120704T101928
113 B A A DISK 04-JUL-12 1 1 YES TAG20120704T101935
115 B F A DISK 04-JUL-12 1 1 NO TAG20120704T101938 |
|
Note: Backupset 111 & 112 contains the datafiles. |
|
If you want to see what the whole backupsets contain, use the following command (list backup or list backupset) to see the entire backupsets. |
|
RMAN> list backup; /* { RMAN> list backupset; } will provide the same result as { RMAN> list backup; } */
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
111 Full 1.01M DISK 00:00:00 04-JUL-12
BP Key: 111 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101928
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3fnf835g_111_1
List of Datafiles in backup set 111
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 260663 04-JUL-12 /u02/oradata/dbuat01/data/tbs_users_01.dbf
5 Full 260663 04-JUL-12 /u02/oradata/dbuat01/data/ts_arun_01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
112 Full 34.48M DISK 00:00:03 04-JUL-12
BP Key: 112 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101928
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3gnf835g_112_1
List of Datafiles in backup set 112
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_system_01.dbf
2 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_sysaux_01.dbf
3 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_undotbs01_01.dbf
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
113 2.00K DISK 00:00:00 04-JUL-12
BP Key: 113 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101935
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745975_3hnf835n_113_1
List of Archived Logs in backup set 113
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 53 260657 04-JUL-12 260671 04-JUL-12
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
115 Full 9.58M DISK 00:00:01 04-JUL-12
BP Key: 115 Status: AVAILABLE Compressed: NO Tag: TAG20120704T101938
Piece Name: /u02/oradata/backup/dbuat01/rman/dbuat01_c-2689589391-20120704-07
SPFILE Included: Modification time: 04-JUL-12
SPFILE db_unique_name: DBUAT01
Control File Included: Ckp SCN: 260686 Ckp time: 04-JUL-12 |
|
Note: As mentioned earlier, BS 111 & 112 contain the datafiles, BS 113 contains archived logs, BS 115 contains the controlfile and spfile. (BS 114 - perhaps used for snapshot controlfile which is not reflecting here) |
|
The following command will list only the datafiles. |
|
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
111 Full 1.01M DISK 00:00:00 04-JUL-12
BP Key: 111 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101928
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3fnf835g_111_1
List of Datafiles in backup set 111
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 260663 04-JUL-12 /u02/oradata/dbuat01/data/tbs_users_01.dbf
5 Full 260663 04-JUL-12 /u02/oradata/dbuat01/data/ts_arun_01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
112 Full 34.48M DISK 00:00:03 04-JUL-12
BP Key: 112 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101928
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3gnf835g_112_1
List of Datafiles in backup set 112
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_system_01.dbf
2 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_sysaux_01.dbf
3 Full 260664 04-JUL-12 /u02/oradata/dbuat01/data/tbs_undotbs01_01.dbf |
|
If you want to list the backed up archive logs |
|
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
113 2.00K DISK 00:00:00 04-JUL-12
BP Key: 113 Status: AVAILABLE Compressed: YES Tag: TAG20120704T101935
Piece Name: /u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745975_3hnf835n_113_1
List of Archived Logs in backup set 113
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 53 260657 04-JUL-12 260671 04-JUL-12 |
|
|
5. Crosschecking the backup/backupsets |
|
A bunch of commands can determine if the backup files (based on the controlfile metadata) are physically present or not. |
|
RMAN> crosscheck backup;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3fnf835g_111_1 RECID=111 STAMP=787745968
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3gnf835g_112_1 RECID=112 STAMP=787745968
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745975_3hnf835n_113_1 RECID=113 STAMP=787745975
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/dbuat01_c-2689589391-20120704-07 RECID=115 STAMP=787745978
Crosschecked 4 objects |
|
Note: 'AVAILABLE' - indicates that the backup is available on disk. If the backup is physically not present in the disk, it will indicate as 'EXPIRED'. It should be confused with 'OBSOLETE' which means that the backup is falling outside the retention window, hence not required. |
|
Crosschecks only the backupsets containing datafiles. |
|
RMAN> crosscheck backupset of database;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3fnf835g_111_1 RECID=111 STAMP=787745968
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745968_3gnf835g_112_1 RECID=112 STAMP=787745968
Crosschecked 2 objects |
|
To verify if the archive logs are physically present in the location as specified in the initialization parameter. |
|
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
validation succeeded for archived log
archived log file name=/u02/oradata/dbuat01/archived_logs/dbuat01_1_53_786023887.arc RECID=47 STAMP=787745975
Crosschecked 1 objects |
|
To verify if the backupset containing the archivelog is physically present. (Notice the difference between this command and the earlier command) |
|
RMAN> crosscheck backup of archivelog all;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/DBUAT01_rman_bkp_20120704_787745975_3hnf835n_113_1 RECID=113 STAMP=787745975
Crosschecked 1 objects |
|
To verify if the backupset containing the CONTROLFILE is physically present. |
|
RMAN> crosscheck backup of controlfile;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/dbuat01_c-2689589391-20120704-07 RECID=115 STAMP=787745978
Crosschecked 1 objects |
|
To verify if the backupset containing the SPFILE is physically present which is obviously the result of the previous command, because SPFILE is always combined with the CONTROLFILE backupset. |
|
RMAN> crosscheck backup of spfile;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u02/oradata/backup/dbuat01/rman/dbuat01_c-2689589391-20120704-07 RECID=115 STAMP=787745978
Crosschecked 1 objects |
|
[ Top ] |
|
Last modified: Jul 05, 2012 11:45 IST |
No comments:
Post a Comment