You are on page 1of 22

2014

How to Perform hot backup for Oracle 10G


Lesson is done on windows 8 and the oracle is enterprise edition 10G

Performing Hot backup on Oracle 10G:


The following lesson contains a scenario of all the steps needed to be known for Oracle Database Administrator to successfully perform hot backup on oracle10G and the same steps can be applied to oracle 11G. Before starting the lesson, there are couple of important points need to be kept in mind: 1- Cold Backup: cold backup is a manual backup and some name it the most reliable one, but it requires shutting down the database and then, make a full copy of everything related to database; data files, log files, and also, control files. But such method can be applied on small businesses databases. 2- Hot backup: hot backup is more reliable backup method and it can be down while the database is running; the term hot is referred to the performance while the database is running. Usually, it is applied in enterprise environments where database cannot be taken offline or shutdown. The following lesson will mainly talk about the procedures commonly followed to accomplish such task. 3- Recovery Manager backup: RM is the method used by database experts to perform backup and we will be talking about it more in detail later inshallah. 4- Data Guard: it is the most newly developed method of backup for database and it is a topic I am willing to discuss later inshallah. note: The following lesson is made on windows 8 and most codes will appear in the CMD window, and please write commands on this lesson as you go on with your reading to make sure all the steps are fully understood. Hot backup of Oracle 10G: We have our database installed on the following path: e:\oracle\product\10.2.0\oradata\ahmed\ we have a subfolder called: Archived_logs and will get to explaining its importance later. we will design a backup folder at the following path: e:\backup\
2

we will also have a subfolder called: archived_logs below it just like the main database folder. Lets Get started: * defining the paths:

as you can see, all my database files are stored in the path specified, and lets now check the archived_logs folder:

we will see a lot of log files saved, what we will do now is removing our archived_logs files and it is done through the following command:
3

We have removed all the log files saved in the archived_logs. Checking our backup paths now:

We viewed the backup folder and then, made a directory and named it archived_logs. We are set now to log into our database and learn the steps:
4

We connected to the database as sys user and it is the highest privilege and then, we queried the database name and the log_mode. the log_mode says "noarchivelog", and it means the database is not in the hot backup mode, and there is an additional step we need to know about before changing the noarchivelog into archivelog; Please check the following code:

It says that our log mode is no archive mode, and the automatic archival is disabled. There is archive destination already set, but it was the test before making this lesson; we need to assume there was no archive destination set before; if there was no archive destination before, how can we set it; the subfolder we have under ahmed folder "archived_logs" is our target archive destination, and it is the same as the one you are seeing in the diagram above. Lets perform the same code again for illustration:

We have set the archive destination successfully, but what is log_archive_dest_1? it is a parameter a database checks to see if there are log files it can read and each log archive log means a point in time. to check the parameter, we can perform the following command:

Since we are done setting our archive destination, we need to set our database into the archivelog mode because it is the mode we have to be in order to take hot backup and by hot backup, it means copying our files safely while the database is running. How do we change our database mode? First we need to shutdown our database, then, startup mount, and finally, issue the command alter database archivelog. after this taks, we can open our database as the following image explains:

How can we check to see if our database in archivelog or not? to do so, we should be issuing the following command:

Since we are already in the archive log, does that mean our database is performing backup already? to answer this question, being in hot backup mode does not mean the database is automatically backing itself up, it is only putting the database in the backup mode. since we are in the backup mode, we can now copy our DBF files into the e:\backup\ folder while the database is running:

We have copied our DBF files into our backup folder "E:\backup\" while the database is running. Is what we did write? The answer is no, your hot backup is not right because you were suppose to inform the database about the backup plan you are about to do. the backup is not active, and as a result, your datafiles are not backed up correctly. What should we do to perform a correct backup? Lets view the following code:

As you can see, the status is "NOT ACTIVE" meaning, the backup we performed earlier is not correct. So in order to perform a correct backup, we need to change our database status into active.

As you can see, our database is now in active hot backup mode, and now we can make our copies into the backup folder, and of course, we need to copy the DBF files:

We have successfully backed up our data files, and after finishing this step, we can stop the backup as the following code shows:

What should we do after finishing this step? We need to make a copy of our controlfile into the backup folder, and the copy should be binary, it can not be done through the Operating system level. The binary controfile backup should be binary and created by the database; the following code shows you how the binary copy can be done:

What does it mean? The database creates a binary control file and names it controlbackup and the path is: "e:\backup". We are going to make a scenario now and then, make our database crash to see how our database will restored through our made backup; we will be observing the changes on our archive logs and their sequence numbering system as well:

11

The archived_logs folder is empty but as we make our scenario, we will be observing some changes in our logs numbers:

We created a table called emp, and then issued the command: " alter system archive log current", and what it does it adds a log file about this point in time and to make sure, we will view the archived_logs in Ahmed folder:

Let's now insert records and after each insertion, we should issue the command: alter system log archive current;

Lets view the archived_logs folder to see if a new log has been added or not:

11

it is successfully added, we will do it four more times, and of course, numbering will be in sequence respectively, so four more times, it means will add 5, 6, 7, and 8, lets do it now:

If we check the archived_logs folder, we will see 5, 6, 7, and 8 added: 12

We will shutdown our database and delete its files from ahmed, and before that, lets copy the log files into their backup folder:

We copied our log files into e:\backup\archived_logs Lets make sure our log files are backed up successfully there.

Now, lets shutdown abort, and then, delete all our files from ahmed folder, and see how it will work: 13

We have deleted all the files, and now, lets try to connect to our database as sysdba:

The database is not responding because it was unable to locate the controlfile, lets now copy our backup from e:\backup to ahmed folder of our database:

14

we have backed up our data files along with the binary controlfile and renaming is very important...... Here is how we rename it dear.

15

if you notice, we change the controlbackup to control01.ctl and then, made two copies of the same controlfile. We have not taking backup of the log files yet, but we will try to start our database now:

We need to define resetlogs or noresetlogs to open our database: in this case, we will use norestlogs now:

16

When we tried to open our database with noresetlogs, we got a recovery request using backup controlfile option; So we need to make a copy our our log files and paste it in the archived_logs, the copy will be taken from e:\backup\archived_logs

We have taken a copy, now we should startup mount our database and then, recover database until cancel using backup controlfile command as it follows:

17

After this, we opened our database in ready only mode because resetlogs is issued when everything is stored properly; Please check the following diagram:

18

We reset log 3, and it confirmed our emp table, but there are no data saved inside; lets now shutdown our database and startup mount and recover database until cancel using backup controlfile and restore number 4:

We approved sequence 4 and when we were asked for 5, we canceled. Then we started our database open in read only mode: Lets check the emp table now:

19

As you can see, in sequence 3, we have the table, but it doesn't contain data, when we recovered sequence 4, we found Ahmed record inserted. Lets now shutdown our database and startup mount, and recover sequence 5:

Lets check the emp table to see if more records are added and in this case, it should have one more record, according to our plan:

21

So, now, we will shutdown the database and restore all logs and open the database with resetlogs option:

I highlighted the alter database open resetlogs because we didn't resetlogs before to be able to recover the rest of our log files, issuing the resetlogs makes the database ignore the remaining, so we used read only to be able to recover more logs as we observe the change in our database. Lets view the table now: 21

We know now, Mohammed is log 6, Faisal is log 7, and finally, Qais is log 8. as for 9 we were asked to approve while recovering, it tells us the following: we need to be aware of the log sequences while recovering. in our case, we have 8, so we can restore 8, when we are asked to approve a high log sequence, we should hit cancel. This is a very important lesson and we should keep it as a references. Some notes to keep in mind: 1- always run your CMD command prompt as administrator. 2- sqlplus /nolog is not sufficient enough to start or shutdown the database, so you need to always connect as sqlplus / as sysdba Best of luck and inshallah more to come.

22

You might also like