Вы находитесь на странице: 1из 4

Cloning steps

 
    Switching Logs
 
We need to make sure that all the present online logs are switched and archived, so that
the time to do the media recovery to the cloned database is as small as possible.
Query the number of log groups that exists in the database and switch as many times as
there are log groups.
 
    select group#,archived,status from v$log
 
GROUP# ARCHIVED STATUS
1 YES INACTIVE
2 NO CURRENT
We can see from the example above, we need to switch logs two times to archive the
online logs.
    alter system switch logfile
     System altered.
Make sure that no log group shows a “STALE” status.
  
Destination Directory structure creation
 Create the destination directory structures as you would like to move the data files and
redo log files. Also create the dump directory to hold the target database dumps (udmp,
bdump cdump, adump etc).
Let’s note down the last archive log file from the archive log destination directory or
from the alert log and then do another
     Alter system switch logfile;
 
  This would give us the current log that got archived by switching and also a checkpoint
occurs. Remember that switching leads to check pointing and check pointing not
necessarily need lead to a log switch. So the data files all get consistent since the current
scn’s are stamped. We do the switch to the number of log groups we have. That means
the first archive log file that was switched might be your full file size and the subsequent
ones would have lesser size depending on the data. 
 
Copy source database files to the target
 
 The next step is to copy all the data files of the source database to the destination
database directories.
Before starting to copy the files of a particular tablespace, we need to put that tablespace
into hot backup mode.
By putting a tablespace into hot backup mode, we will ensure two things.
1)      The first time a block is changed in a data file that is in hot backup mode, the entire
block is written to the redo log files, not just the changed bytes. Normally only the
changed bytes (a redo vector) are written. In hot backup mode, the entire block is logged
the first time. This is because you can get into a situation where the process copying the
data file and DBWR are working on the same block simultaneously.
2)      The data file headers which contain the SCN of the last completed checkpoint are not
updated while a file is in hot backup mode. This lets the recovery process understand
what archive redo log files might be needed to fully recover this file.
 
To limit the effect of this additional logging, you should ensure you only place one
tablespace at a time in backup mode and bring the tablespace out of backup mode as soon
as you have backed it up. This will reduce the number of blocks that may have to be
logged to the minimum possible. 
List out all the tablespaces present in the system and their corresponding data files.
    select tablespace_name,status,contents from dba_tablespaces
 
TABLESPACE_NAME STATUS CONTENTS
SYSTEM ONLINE PERMANENT
UNDOTBS1 ONLINE UNDO
SYSAUX ONLINE PERMANENT
TEMP ONLINE TEMPORARY
USERS ONLINE PERMANENT
FLIRT ONLINE PERMANENT
6 rows selected.
select tablespace_name,file_name from dba_data_files order by tablespace_name
TABLESPACE_NAME FILE_NAME
FLIRT C:\FLIRT\DBFILES\FLIRT01.DBF
SYSAUX C:\FLIRT\DBFILES\SYSAUX01.DBF
SYSTEM C:\FLIRT\DBFILES\SYSTEM01.DBF
UNDOTBS1 C:\FLIRT\DBFILES\UNDOTBS01.DBF
USERS C:\FLIRT\DBFILES\USERS01.DBF
 Now put each tablespace into hot backup mode, copy it’s corresponding data files to the
destination directory, and then bring out the tablespace from the hot backup mode, one
tablespace at a time.  Alter tablespace FLIRT begin backup;
!copy C:\FLIRT\DBFILES\FLIRT01.DBF C:\VALEN\DBFILES\FLIRT01.DBF
Alter tablespace FLIRT end backup;
 
 It is better to do the above exercise using a script, so that manual intervention, and hence, chance of committing an error, is also less.
 Following is a script that you can use to generate a hot backup copy script from any database
set serveroutput on
set heading off
set feedback off
spool c:\scripts\backup.sql
declare
  fn varchar2(55);
  tn1 varchar2(55);
  tn2 varchar2(55);
  cursor tsp is
  select tablespace_name,file_name from v$datafile,sys.dba_data_files
  where enabled like '%WRITE%' and file# = file_id
  order by 1;
begin
  dbms_output.enable(32000);
  dbms_output.put_line('spool hotbackup.sql');
  open tsp;
    fetch tsp into tn1,fn;
    tn2 := tn1;
    dbms_output.put_line('alter tablespace '||tn1||' begin backup;');
    while tsp%FOUND loop
      if tn2 != tn1 then
        dbms_output.put_line('alter tablespace '||tn2||' end backup;');
        dbms_output.put_line('alter tablespace '||tn1||' begin backup;');
        tn2 := tn1;
      end if;
      dbms_output.put_line('!copy '||fn||' c:\VALEN\DBFILES\');
      --Change the line above line with o.s specific copy command.
      fetch tsp into tn1,fn;
    end loop;
    dbms_output.put_line('alter tablespace '||tn2||' end backup;');
  close tsp;
  dbms_output.put_line('spool off');
end;
/
spool off
set heading on
set feedback on
set serveroutput off
 
 
Switch logs again
Once again, once the copy is complete, switch log groups the required number of times. In this way we need to copy over only those archive files
starting with the ones that we noted down when we started the log switch to the ones we have when we did the log switch after the backup. These
would be very few and hence the recovery would also be faster when we apply these archive files. We would also have a set of archive files that we
are sure of and consistency can thus be assured.
  
Backup the Control File.
 Now we need a control file creation script for the target database. The best way to achieve this is to backup the source control file to trace with the
following command.
 
    alter database backup controlfile to trace
        Database altered.
 
Copy the appropriate archive logs and online redo logs to the target location.
 
Prepare Initialization Parameter File
 
 Make appropriate changes to the initialization parameter file of the target db to reflect the
new file locations and new database. Create appropriate target dump locations (adump,
bdump, udump etc).
 
Creating Service and control files in target
 
 Set the sid to the target database.
If the target host is windows, then you will need to create database service control with the oradim command. Use the following syntax to create the
service.
 Oradim –new –sid <target db name> -intpwd <sys password> -startmode manual
start a sqlplus session as sysdba and start the instance in nomount mode with target init
 

file.
Open the control file trace backup. Towards the end, you’ll find controlfile creation
statement with resetlogs option .Following is an example:
 CREATE CONTROLFILE reuse DATABASE "FLIRT" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 2920
LOGFILE
  GROUP 1 'C:\FLIRT\REDO1\REDO01.LOG'  SIZE 5M,
  GROUP 2 'C:\FLIRT\REDO2\REDO02.LOG'  SIZE 5M
-- STANDBY LOGFILE
DATAFILE
  'C:\FLIRT\DBFILES\SYSTEM01.DBF',
  'C:\FLIRT\DBFILES\UNDOTBS01.DBF',
  'C:\FLIRT\DBFILES\SYSAUX01.DBF',
  'C:\FLIRT\DBFILES\USERS01.DBF',
  'C:\FLIRT\DBFILES\FLIRT01.DBF',
  'C:\FLIRT\DBFILES\DGOD01.DBF'
CHARACTER SET WE8MSWIN1252
;
 
Change the first line of the statement to look like this :
CREATE CONTROLFILE set DATABASE "VALEN" RESETLOGS  ARCHIVELOG ……..
Also change the file locations of the database mentioned in the statement to reflect the
target file location.
After all the changes to the statement, it should look like following :
CREATE CONTROLFILE set DATABASE "VALEN" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 2920
LOGFILE
  GROUP 1 'C:\valen\REDO1\REDO01.LOG'  SIZE 5M,
  GROUP 2 'C:\valen\REDO2\REDO02.LOG'  SIZE 5M
-- STANDBY LOGFILE
DATAFILE
  'C:\valen\DBFILES\SYSTEM01.DBF',
  'C:\valen\DBFILES\UNDOTBS01.DBF',
  'C:\valen\DBFILES\SYSAUX01.DBF',
  'C:\valen\DBFILES\USERS01.DBF',
  'C:\valen\DBFILES\flirt01.DBF',
  'C:\valen\DBFILES\DGOD01.DBF'
CHARACTER SET WE8MSWIN1252

Go the sqlplus session and execute the above (changed) controlfile creation statement to
create the controlfiles.
Controlfile should be created without any errors.
 
Apply Media Recovery
         Now you need to apply media recovery to make the database consistent. Execute
the following statement.
       RECOVER DATABASE USING BACKUP CONTROLFILE;
You may need to apply the online redo logs to make the media recovery complete.
After media recovery is complete open the database in restelogs mode.
      Alter database open resetlogs;
Add tempfiles to the temporary tablespaces.
ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\valen\DBFILES\TEMP01.DBF'
 SIZE 20971520  REUSE AUTOEXTEND OFF;
 
Cloning is complete.

Вам также может понравиться