Backup Controlfile
Since the controlfile is a very busy file on reading and writing when your database is open, you can't copy the file directly to another place. Instead, you should use SQL or RMAN to snapshot online controlfile out of the database. This will make the file consistent.
In this post, we introduce some ways to backup controlfile as followings.
SQL Backup
You can use SQL statement to backup a copy of controlfile to a specific location.
SQL> alter database backup controlfile to '/tmp/primdb1-20181025.ctl';
Database altered.
SQL> !ls -l /tmp/primdb1-20121212-2.ctl
-rw-r----- 1 oracle asmadmin 19709952 Oct 25 16:24 /tmp/primdb1-20181025.ctl
RMAN Backup Copy
Use the following statement to get a copy of current controlfile.
RMAN> backup as copy current controlfile format '/tmp/primdb1-20121212.ctl';
Starting backup at 12-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=98 instance=primdb1 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/tmp/primdb1-20121212.ctl tag=TAG20121212T162940 RECID=16 STAMP=801851384
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 12-DEC-12
Starting Control File and SPFILE Autobackup at 12-DEC-12
piece handle=+DATA/primdb/autobackup/2012_12_12/s_801851388.1110.801851393 comment=NONE
Finished Control File and SPFILE Autobackup at 12-DEC-12
Please note that, the above copies can be used directly. No need to restore before using it, just copy it to the destination specified in SPFILE.
Above copies of the current controlfile will be regarded as BACKUP controlfiles, not CURRENT if we use them to recover databases.
RMAN Backup Piece
We can also backup the controlfile as a backup piece.
CONTROLFILE
RMAN> backup current controlfile format '/backup/control-%U';
Starting backup at 29-NOV-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 29-NOV-18
channel ORA_DISK_1: finished piece 1 at 29-NOV-18
piece handle=/backup/control-030fds04_1_1 tag=TAG20181129T205844 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-NOV-18
SPFILE + CONTROLFILE
In practice, we backup SPFILE as well as the controlfile in the same backup piece.
RMAN> backup spfile include current controlfile format '/backup/control-%U';
Starting backup at 29-NOV-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1730 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 29-NOV-18
channel ORA_DISK_1: finished piece 1 at 29-NOV-18
piece handle=/backup/control-050fe07q_1_1 tag=TAG20181129T221106 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-NOV-18
In this case, SPFILE and controlfile are backed up in the same backup piece because of using only 1 backup channel.
For RMAN backups which have more degrees of parallelism (DOP), we expect 2 backup pieces, one for each file. For example:
[oracle@test ~]$ ll /backup
total 43680
-rw-r----- 1 oracle oinstall 22347776 Nov 29 20:58 control-030fds04_1_1
-rw-r----- 1 oracle oinstall 22380544 Nov 29 22:11 control-050fe07q_1_1
The backup piece of controlfile containing SPFILE is a little bigger than the other.
DATABASE + CONTROLFILE
We backup the whole database with the current controlfile.
RMAN> backup database include current controlfile format '/backup/%U';
DATABASE + CONTROLFILE + ARCHIVELOG
We backup the whole database with the current controlfile and required archived logs.
RMAN> backup database include current controlfile format '/backup/%U' plus archivelog format '/backup/%U';
This could be the very self-contained full backup.
RMAN AUTOBACKUP
Setting AUTOBACKUP ON in RMAN will enable the database to backup the controlfile to specific path automatically whenever the definition of database is changed.
If there's anything wrong, you can restore controlfile by those backups.