RMAN is a backup and recovery manager supplied for Oracle databases created by the Oracle Corporation. It provides database backup, restore, and recovery capabilities addressing high availability and disaster recovery concerns and since RMAN uses human-like language for interpreting the command you simply type the:
$ backup database;
that’s all. but we wanted to be more precise in case you may lose or something unexpected happened to “control file” you can do the following:
$ rman target /
$ RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
$ RMAN> BACKUP DATABASE PLUS ARCHIVELOG or BACKUP AS BACKUPSET DATABASE PLUS ARCHIVELOG;
you can also give name to your backups by adding a tag name:
$ RMAN> BACKUP DATABASE TAG ${YOUR_TAG_NAME};
also you can change your backup folder in two ways, ONE is to change youe backup directory in RMAN , second is in your script give the backup folder which are as the followings :
$ RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/rman/full_%u_%s_%p';
OR
run {
allocate channel d1 type disk;
backup format '/YOUR/PATH/FOR/BACKUP/%U.bkp' database plus archivelog;
release channel d1;
}
NOTE : in order to do the “RESTORING” your database need to be in “MOUNT” state and it will be done:
If database is running, you need to shut it down.
shutdown transactional;
startup mount;
There are multiple ways of restoring with RMAN but you need to know how many backups do you have so lets list’em
$ RMAN> list backup;
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 245.06G DISK 00:25:34 02-FEB-15
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20150202T171725
Piece Name: /oradata/oradata/backup_rman/04pu9f96_1_1.bkp
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 238879810 02-FEB-15 /flash_recovery_area/oradata/system01.dbf
2 Full 238879810 02-FEB-15 /flash_recovery_area/oradata/sysaux01.dbf
3 Full 238879810 02-FEB-15 /flash_recovery_area/oradata/undotbs01.dbf
4 Full 238879810 02-FEB-15 /flash_recovery_area/oradata/users01.dbf
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4 1.56M DISK 00:00:00 02-FEB-15
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20150202T174304
Piece Name: /oradata/oradata/backup_rman/05pu9gp8_1_1.bkp
List of Archived Logs in backup set 4
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 8 238879587 02-FEB-15 238882605 02-FEB-15
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5 Full 9.11M DISK 00:00:00 02-FEB-15
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20150202T174305
Piece Name: /flash_recovery_area/oradata/autobackup/2015_02_02/o1_mf_n_870630185_bdz1hkgr_.bkp
Control File Included: Ckp SCN: 238882614 Ckp time: 02-FEB-15
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6 Full 9.11M DISK 00:00:00 04-FEB-15
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20150204T152731
Piece Name: /flash_recovery_area/oradata/autobackup/2015_02_04/o1_mf_n_870794851_bf429cs9_.bkp
Control File Included: Ckp SCN: 238882801 Ckp time: 04-FEB-15
Well that’s too many data so lets summarize it
$ RMAN> list backup summary;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
2 B A A DISK 02-FEB-15 1 1 NO TAG20150202T171723
3 B F A DISK 02-FEB-15 1 1 NO TAG20150202T171725
4 B A A DISK 02-FEB-15 1 1 NO TAG20150202T174304
5 B F A DISK 02-FEB-15 1 1 NO TAG20150202T174305
6 B F A DISK 04-FEB-15 1 1 NO TAG20150204T152731
Now that we can see our backups lets restore
- Tag Name
$ RMAN> restore database from tag '${TAG_NAME}';
Usually tag uses the time format : TAG2015-02-02-T17:17:23
- Date
$ RMAN> restore database until time "to_date('26-jun-2014 9:53:00', 'dd-mon-rrrr hh24:mi:ss')";
$ RMAN> recover database until time "to_date('26-jun-2014 9:53:00', 'dd-mon-rrrr hh24:mi:ss')";
$ RMAN> alter database open resetlogs;