{"id":127,"date":"2020-10-27T15:25:18","date_gmt":"2020-10-27T15:25:18","guid":{"rendered":"https:\/\/maboc.nl\/?p=127"},"modified":"2020-10-27T15:25:18","modified_gmt":"2020-10-27T15:25:18","slug":"restore-and-recover-a-database-when-everything-is-gone","status":"publish","type":"post","link":"https:\/\/maboc.nl\/?p=127","title":{"rendered":"Restore and recover a database when everything is gone"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">Today someone deleted everything: datafiles gone, controlfile gone, spfile gone. What to do?&#8230;..not to worry&#8230;.if you have backups (and the logging of those backups) you can get everything back \ud83d\ude42<\/p>\r\n<ol>\r\n<li>Lookup your DBID<\/li>\r\n<li>Lookup the autobackup file you want to use (probably the latest)<\/li>\r\n<li>Startup database nomount from a init.ora (spfile is also possible but involves extra work)<\/li>\r\n<li>Restore spfile from autobackup<\/li>\r\n<li>Restart the database nomount<\/li>\r\n<li>Restore controlfiles from autobackup<\/li>\r\n<li>Restart database mount<\/li>\r\n<li>Restore database<\/li>\r\n<li>Recover database<\/li>\r\n<li>Alter database open resetlogs<\/li>\r\n<\/ol>\r\n<p>Find the DBID in the logging of your backups or in filename the AutoBackup file.<\/p>\r\n<p>Loggin:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">[oracle@bloemkool log]$ head backup.20201027-153002.CDB01.arch.log <br \/>The Oracle base has been set to \/u01\/app\/oracle<br \/><br \/>Recovery Manager: Release 19.0.0.0.0 - Production on Tue Oct 27 15:30:02 2020<br \/>Version 19.3.0.0.0<br \/><br \/>Copyright (c) 1982, 2019, Oracle and\/or its affiliates. All rights reserved.<br \/><br \/>connected to target database: CDB01 (DBID=<span style=\"color: #ff0000;\">1590200411<\/span>)<br \/>using target database control file instead of recovery catalog<br \/><br \/>[oracle@bloemkool log]$<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>Or have a look at the name of the autobackup file:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">[oracle@bloemkool bloemkool]$ ls -altr | tail -10<br \/>-rw-r----- 1 nobody nobody 27623424 Oct 27 11:30 c-<span style=\"color: #ff0000;\">1590200411<\/span>-20201027-0c<br \/>-rw-r----- 1 nobody nobody 7008768 Oct 27 12:30 7lve12ah_1_1<br \/>-rw-r----- 1 nobody nobody 27623424 Oct 27 12:30 c-<span style=\"color: #ff0000;\">1590200411<\/span>-20201027-0d<br \/>-rw-r----- 1 nobody nobody 7062016 Oct 27 13:30 7nve15r3_1_1<br \/>-rw-r----- 1 nobody nobody 27623424 Oct 27 13:30 c-<span style=\"color: #ff0000;\">1590200411<\/span>-20201027-0e<br \/>-rw-r----- 1 nobody nobody 7263744 Oct 27 14:30 7pve19bi_1_1<br \/>-rw-r----- 1 nobody nobody 27623424 Oct 27 14:30 c-<span style=\"color: #ff0000;\">1590200411<\/span>-20201027-0f<br \/>-rw-r----- 1 nobody nobody 7227904 Oct 27 15:30 7rve1cs4_1_1<br \/>drwxrwxrwx 2 nobody nobody 12288 Oct 27 15:30 .<br \/>-rw-r----- 1 nobody nobody 27623424 Oct 27 15:30 c-<span style=\"color: #ff0000;\">1590200411<\/span>-20201027-10<br \/>[oracle@bloemkool bloemkool]$<\/pre>\r\n<p>Now we allready see what is the latest Autobackup file :\u00a0 c-1590200411-20201027-10<\/p>\r\n<p>To be sure we also take a look at the backup logging:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">[oracle@bloemkool log]$ tail backup.20201027-153002.CDB01.arch.log<br \/>archived log file name=\/u03\/archiving\/CDB01\/1_136_1054737965.dbf RECID=4535 STAMP=1054913412<br \/>Finished backup at 27-OCT-20<br \/><br \/>Starting Control File and SPFILE Autobackup at 27-OCT-20<br \/>piece handle=<span style=\"color: #ff0000;\">\/u04\/backups\/bloemkool\/c-1590200411-20201027-10<\/span> comment=NONE<br \/>Finished Control File and SPFILE Autobackup at 27-OCT-20<br \/><br \/>RMAN&gt;<br \/><br \/>Recovery Manager complete.<br \/>[oracle@bloemkool log]$<\/pre>\r\n<p>We now have what we need.<\/p>\r\n<p>Let&#8217;s startup the database in nomount mode. Starting up from an (old)\u00a0 spfile is certainly possible. However&#8230;if you startup from an spfile, RMAN will complain that it can not replace a spfile if the database started up from that file. The easiest way is starting from an init.ora which probably jusr resides in your $ORACLE_HOME\/dbs.<\/p>\r\n<p>Startup the database in nomount(this can conviniently be done from the RMAN Command Line):<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">[oracle@bloemkool dbs]$ rman target \/ nocatalog<br \/><br \/>Recovery Manager: Release 19.0.0.0.0 - Production on Tue Oct 27 15:55:17 2020<br \/>Version 19.3.0.0.0<br \/><br \/>Copyright (c) 1982, 2019, Oracle and\/or its affiliates. All rights reserved.<br \/><br \/>connected to target database (not started)<br \/><br \/>RMAN&gt; startup force nomount;<br \/><br \/>Oracle instance started<br \/><br \/>Total System Global Area 620756648 bytes<br \/><br \/>Fixed Size 9137832 bytes<br \/>Variable Size 281018368 bytes<br \/>Database Buffers 327155712 bytes<br \/>Redo Buffers 3444736 bytes<br \/>RMAN&gt;<br \/><br \/><\/pre>\r\n<p>Set The DBID we found earlier:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\"><br \/>RMAN&gt; set dbid=1590200411<br \/><br \/>executing command: SET DBID<br \/><br \/>RMAN&gt; <\/pre>\r\n<p>Restore the spfile from the Autobackup file we found:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; restore spfile from '\/u04\/backups\/bloemkool\/c-1590200411-20201027-10';<br \/><br \/>Starting restore at 27-OCT-20<br \/>allocated channel: ORA_DISK_1<br \/>channel ORA_DISK_1: SID=427 device type=DISK<br \/><br \/>channel ORA_DISK_1: restoring spfile from AUTOBACKUP \/u04\/backups\/bloemkool\/c-1590200411-20201027-10<br \/>channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete<br \/>Finished restore at 27-OCT-20<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>Startup the database again in nomount (however the spfile is back&#8230;so we now have some initialisation done. For example &#8230;. the location of the control-files)<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; startup force nomount;<br \/><br \/>Oracle instance started<br \/><br \/>Total System Global Area 620756648 bytes<br \/><br \/>Fixed Size 9137832 bytes<br \/>Variable Size 184549376 bytes<br \/>Database Buffers 423624704 bytes<br \/>Redo Buffers 3444736 bytes<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>Restore the controlfile(s) from the Autobackup file:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; restore controlfile from '\/u04\/backups\/bloemkool\/c-1590200411-20201027-10';<br \/><br \/>Starting restore at 27-OCT-20<br \/>allocated channel: ORA_DISK_1<br \/>channel ORA_DISK_1: SID=427 device type=DISK<br \/><br \/>channel ORA_DISK_1: restoring control file<br \/>channel ORA_DISK_1: restore complete, elapsed time: 00:00:01<br \/>output file name=\/u01\/multiplex\/CDB01\/controlfile\/o1_mf_hqwfqvkb_.ctl<br \/>output file name=\/u02\/multiplex\/CDB01\/controlfile\/o1_mf_hqwfqvp8_.ctl<br \/>output file name=\/u03\/multiplex\/CDB01\/controlfile\/o1_mf_hqwfqvtq_.ctl<br \/>Finished restore at 27-OCT-20<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>Now restart the datbase in mount mode. We now have a controlfile, all backup information resides in the controlfiles:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; startup force mount;<br \/><br \/>Oracle instance started<br \/>database mounted<br \/><br \/>Total System Global Area 620756648 bytes<br \/><br \/>Fixed Size 9137832 bytes<br \/>Variable Size 192937984 bytes<br \/>Database Buffers 415236096 bytes<br \/>Redo Buffers 3444736 bytes<br \/><br \/>RMAN&gt; <\/pre>\r\n<p>Restore the database:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; restore database;<br \/><br \/>Starting restore at 27-OCT-20<br \/>Starting implicit crosscheck backup at 27-OCT-20<br \/>allocated channel: ORA_DISK_1<br \/>channel ORA_DISK_1: SID=431 device type=DISK<br \/>Crosschecked 143 objects<br \/>Finished implicit crosscheck backup at 27-OCT-20<br \/><br \/>Starting implicit crosscheck copy at 27-OCT-20<br \/>using channel ORA_DISK_1<br \/>Crosschecked 3 objects<br \/>Finished implicit crosscheck copy at 27-OCT-20<br \/><br \/>searching for all files in the recovery area<br \/>cataloging files...<br \/>no files cataloged<br \/><br \/>using channel ORA_DISK_1<br \/><br \/>datafile 5 is already restored to file \/u02\/datafiles\/CDB01\/pdbseed\/system01.dbf<br \/>datafile 6 is already restored to file \/u02\/datafiles\/CDB01\/pdbseed\/sysaux01.dbf<br \/>datafile 8 is already restored to file \/u02\/datafiles\/CDB01\/pdbseed\/undotbs01.dbf<br \/>channel ORA_DISK_1: starting datafile backup set restore<br \/>channel ORA_DISK_1: specifying datafile(s) to restore from backup set<br \/>channel ORA_DISK_1: restoring datafile 00001 to \/u02\/datafiles\/CDB01\/system01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00003 to \/u02\/datafiles\/CDB01\/sysaux01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00004 to \/u02\/datafiles\/CDB01\/undotbs01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00007 to \/u02\/datafiles\/CDB01\/users01.dbf<br \/>channel ORA_DISK_1: reading from backup piece \/u04\/backups\/bloemkool\/6ovdvmce_1_1<br \/>channel ORA_DISK_1: piece handle=\/u04\/backups\/bloemkool\/6ovdvmce_1_1 tag=TAG20201027T000014<br \/>channel ORA_DISK_1: restored backup piece 1<br \/>channel ORA_DISK_1: restore complete, elapsed time: 00:00:25<br \/>channel ORA_DISK_1: starting datafile backup set restore<br \/>channel ORA_DISK_1: specifying datafile(s) to restore from backup set<br \/>channel ORA_DISK_1: restoring datafile 00009 to \/u02\/datafiles\/CDB01\/PDB01\/system01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00010 to \/u02\/datafiles\/CDB01\/PDB01\/sysaux01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00011 to \/u02\/datafiles\/CDB01\/PDB01\/undotbs01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00012 to \/u02\/datafiles\/CDB01\/PDB01\/users01.dbf<br \/>channel ORA_DISK_1: restoring datafile 00013 to \/u02\/datafiles\/CDB01\/PDB01\/martijn01.dnf<br \/>channel ORA_DISK_1: reading from backup piece \/u04\/backups\/bloemkool\/6pvdvme0_1_1<br \/>channel ORA_DISK_1: piece handle=\/u04\/backups\/bloemkool\/6pvdvme0_1_1 tag=TAG20201027T000014<br \/>channel ORA_DISK_1: restored backup piece 1<br \/>channel ORA_DISK_1: restore complete, elapsed time: 00:00:15<br \/>Finished restore at 27-OCT-20<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>Recover the database. For brevity a lot of the output is skipped:<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; recover database;<br \/><br \/><br \/>Starting recover at 27-OCT-20<br \/>using channel ORA_DISK_1<br \/><br \/>starting media recovery<br \/><br \/>archived log for thread 1 with sequence 135 is already on disk as file \/u01\/multiplex\/CDB01_BROCCOLI\/onlinelog\/o1_mf_2_hsc0dxz4_.log<br \/>archived log for thread 1 with sequence 136 is already on disk as file \/u01\/multiplex\/CDB01_BROCCOLI\/onlinelog\/o1_mf_3_hsc0f0hp_.log<br \/>archived log for thread 1 with sequence 137 is already on disk as file \/u01\/multiplex\/CDB01_BROCCOLI\/onlinelog\/o1_mf_1_hsc0dxz4_.log<br \/>channel ORA_DISK_1: starting archived log restore to default destination<br \/>channel ORA_DISK_1: restoring archived log<br \/>archived log thread=1 sequence=102<br \/>channel ORA_DISK_1: reading from backup piece \/u04\/backups\/bloemkool\/6rvdvmfd_1_1<br \/>channel ORA_DISK_1: piece handle=\/u04\/backups\/bloemkool\/6rvdvmfd_1_1 tag=TAG20201027T000149<br \/>channel ORA_DISK_1: restored backup piece 1<br \/>channel ORA_DISK_1: restore complete, elapsed time: 00:00:01<br \/>...<br \/><br \/>...<br \/><br \/>...<br \/><br \/>media recovery complete, elapsed time: 00:00:02<br \/>Finished recover at 27-OCT-20<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>Let&#8217;s open the DB up<\/p>\r\n<pre style=\"font-size: smaller; font-family: courier;\">RMAN&gt; alter database open resetlogs;<br \/><br \/>Statement processed<br \/><br \/>RMAN&gt;<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>Yes&#8230;we got it working again!!!!<\/p>\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Today someone deleted everything: datafiles gone, controlfile gone, spfile gone. What to do?&#8230;..not to worry&#8230;.if you have backups (and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5,20],"tags":[24,25,22,26],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-oracle","category-rman","tag-oracle","tag-recover","tag-restore","tag-rman"],"_links":{"self":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":11,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/maboc.nl\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maboc.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}