RMAN oracle database 12c backup script

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarANKUSH THAVALI
  • 06 Jun, 2019
  • 0 Comments
  • 3 Mins Read

RMAN oracle database 12c backup script

Change RMAN backup location

configure channel device type disk format '/data/backup/%U' maxpiecesize 2 G;

SPFILE backups

The SPFILE can be automatically backed up with the control file during database backups by configuring the CONTROLFILE AUTOBACKUP parameters

To backup up the SPFILE explicitly use:

RMAN> BACKUP SPFILE;


Controlfile backups

The current controlfile can be automatically backed up by the BACKUP command by configuring the CONTROLFILE AUTOBACKUP parameters

To backup the current controlfile explicitly use:

RMAN> BACKUP CURRENT CONTROLFILE;


Datafile backups

To backup a specific data file use BACKUP DATAFILE. For example:

RMAN> BACKUP DATAFILE '/data/app/oradata/TEST/users01.dbf';
Altermatively specify the data file number. For example:

RMAN> BACKUP DATAFILE 5;


Archive log backup

BACKUP ARCHIVELOG ALL;


Archive log backup with delete input

BACKUP ARCHIVELOG ALL DELETE INPUT;


Tablespace Backups

To backup a tablespace use the BACKUP TABLESPACE command. For example:

RMAN> BACKUP TABLESPACE USERS;


To create an image copy of a specific datafile use:

RMAN> BACKUP AS COPY DATAFILE 4 FORMAT '/u01/app/oracle/copy/users01.dbf';


Incremental Backups
By default backups are full (level 0). Backups can also be incremental (level 1).

Incremental backups can be:

Differential - includes all changes since the last full or incremental backup
Cumulative - includes all changes since the last full backup
Differential backups require less space. Cumulative backups are faster to restore

Differential backups are the default.

Level 0 Backup - Backup of spfile,control file ,database and archivelog

RUN
{
  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 10G;
  ALLOCATE CHANNEL ch12 TYPE DISK MAXPIECESIZE 10G;
  ALLOCATE CHANNEL ch13 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/data/rman/%d_D_%T_%u_s%s_p%p'
  INCREMENTAL LEVEL 0 DATABASE
  CURRENT CONTROLFILE
  FORMAT '/data/rman/%d_C_%T_%u'
  SPFILE
  FORMAT '/data/rman/%d_S_%T_%u'
  PLUS ARCHIVELOG
  FORMAT '/data/rman/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL ch11;
  RELEASE CHANNEL ch12;
  RELEASE CHANNEL ch13;
}

Level 1 backup


RUN
{
  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 10G;
  ALLOCATE CHANNEL ch12 TYPE DISK MAXPIECESIZE 10G;
  ALLOCATE CHANNEL ch13 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/data/rman/%d_D_%T_%u_s%s_p%p'
  INCREMENTAL LEVEL 1 DATABASE
  CURRENT CONTROLFILE
  FORMAT '/data/rman/%d_C_%T_%u'
  SPFILE
  FORMAT '/data/rman/%d_S_%T_%u'
  PLUS ARCHIVELOG
  FORMAT '/data/rman/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL ch11;
  RELEASE CHANNEL ch12;
  RELEASE CHANNEL ch13;
}

To perform a cumulative incremental backup, use the following command

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

Pluggable Database (PDB) Backup

There are two ways to back up pluggable databases. When connected to RMAN as the root container, you can backup one or more PDBs using the following command.

$ rman target=/

RMAN> BACKUP PLUGGABLE DATABASE pdb1, pdb2;

Alternatively, connect to a specific PDB and issue the following command.

$ rman target=sys@pdb1

RMAN> BACKUP DATABASE;

Tablespace and Datafile Backups

Multiple PDBs in the same CDB can have a tablespace with the same name, for example SYSTEM, SYSAUX and USERS. One way to remove that ambiguity is connect to the appropriate PDB. Once RMAN is connected to the PDB, the tablespace backup commands is unchanged compared to previous versions.

$ rman target=sys@pdb1

RMAN> BACKUP TABLESPACE system, sysaux, users;

SCN Level Backup

SQL> select CURRENT_SCN FROM V$DATABASE;

CURRENT_SCN
———–
4336877

SQL>
SQL>
SQL> select scn_to_timestamp(4336877)as timestamp from dual;

TIMESTAMP
—————————————————————————
04-AUG-21 03.00.21.000000000 PM



RMAN> BACKUP INCREMENTAL FROM SCN 3164433 DATABASE FORMAT ‘/data/rmann_%U’ tag ‘SCNBACKUP’;


RMAN Point in time restoration.

Consider following example, here we are performing DBPITR to the date time : 27-Jan-2019 15:00:00

RMAN> shutdown immediate;

RMAN> startup mount;
connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area 408981760 bytes
Fixed Size 3212896 bytes
Variable Size 392941024 bytes
Database Buffers 109051904 bytes
Redo Buffers 4775936 bytes



For DBPITR “set until time” clause used:

RMAN> RUN {
set until time “to_date(’27-JAN-2019 15:00:00′,’DD-MON-YYYY HH24:MI:SS’)”;
restore database;
recover database;
alter database open resetlogs; }