Wednesday, December 16, 2009

Backing Up Oracle, Easily

As a developer I have a need to replicate environments. As I now work regularly with Oracle, my environment-maintenance duties should include duplicating Oracle databases across various machines. But how in the world do you do that?

It's been a real eye-opener to research what's involved with Oracle administration. I've come to the conclusion that the Oracle company doesn't really bother itself with things like quickstarts. Sadly, all their documentation is written in documentation-ese. What a struggle.

A few days ago I broke down and tackled the Oracle restoration challenge. I finally restored my first Oracle database today, and I thought I'd document how to do it, for the benefit of others. Essentially, I copied files over from the old server to the new one. FYI, this is what as known as a "cold" backup and recovery because the databases are shutdown when the activity occurs.

1. First, run these commands in sqlplus or Sql Developer to find out which files need to be copied:
          select name from v$datafile; -- this provides the datafiles
          select name from v$controlfile; --this provides the control files
2. Note the redo files. They are in the same directory as the datafiles.
3. Now log into the database to be replicated as sysdba
          $>sqlplus "/ as sysdba"
4. And issue the "shutdown abort" command
5. Similarly on the new server, issue the "shutdown abort" command
5. Copy all the files referred to in items 1, 2, and 3 above from the server to be replicated to the corresponding locations on the new server
6. Back in sqlplus on the server to be replicated, issue the "restart" command
7. Do the same for the new server

Congratulations! You should be up and running on the new server by now.