Sunteți pe pagina 1din 8

-

brisanje starih (ve obrisanih) archive log fileova:

RMAN connect target / crosscheck archivelog all; delete expired archivelog all; Scenarij 1: Napravio kopiju baze sa RMAN-om(compressed), obrisao sve file-ove RMAN je napravio 3 file-a: /oradata2/RMAN_Test/04ivesdp_1_1 - datafileovi /oradata2/RMAN_Test/05ivesgf_1_1 - control file, sfile /oradata2/RMAN_Test/06ivesgi_1_1 - archive logovi Obrisao sve vezano uz bazu. Napravio nakakav initTest.ora samo za poetak. rman> rman> rman> rman> rman> rman> rman> rman> rman> rman> connect target startup nomount; restore spfile from '/oradata2/RMAN_Test/05ivesgf_1_1'; vraa spfile s kojim emo podii bazu shutdown immediate startup nomount - diemo bazu sa restoranim spfile-om restore controlfile from '/oradata2/RMAN_Test/05ivesgf_1_1'; vraam contolfile koji ima podatke o backup-u startup mount (moda najprije sruiti bazu) restore database; recover database; alter database open resetlogs;

*RMAN ne kui arhivu Napravio rman online backup. Nakon toga napravio rman backup archive log fileova. Izbrisao bazu. Napravio restore controlfile-a, restore database. Recovery ne moe nai archivelog fileove. Napravio skriptu rman.txt za uvrtenje archivelog fileova u catalog: for i in `ls *` do print CATLOG ARCHIVELOG \'/oradata2/RMAN_Test/$i\'\; >> rman.txt done Izveo skriptu iz RMAN> @rman.txt i nakon toga recovery proe! * korisnik mora imati sysdba dozvolu (po default je ima samo sys). grant sysdba to rman_user; Spajanje na rman rman nocatalog target system/manager rman target sys/sys_pwd@db1 catalog rman_db1/rman_db1@catdb batch: rman target / catalog rm_db1/rm_db1@cat @tbsbk.rcv log tbs.log

Backup i restore baze Test


Baza je na serveru branko. Postavke RMAN-a su bile default-ne osim CONFIGURE CONTROLFILE AUTOBACKUP FORMAT ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata3/RMAN_Test/cf_%F'; jer je default postavka '%F' radila image copy u FRA. Uzeo RMAN backup sa RMAN> backup database plus archivelog; Zapisao DBID iz v$database. Ugasio bazu, pobrisao sve i krenuo. RESTORE: postavio ORACLE_SID i pokrenuo RMAN postavio set DBID=##.### pokrenuo (NOMOUNT) instancu pustio: RMAN> run { set controlfile autobackup format for device type disk to '/oradata3/RMAN_Test/cf_%F'; allocate channel c1 device type disk; restore spfile from autobackup; } - za restore spfile-a ili restore spfile from '/oradata3/RMAN_Test/cf_c-1934450637-20080320-01'; - za restore controlfile-a RMAN> run { set controlfile autobackup format for device type disk to '/oradata3/RMAN_Test/cf_%F'; allocate channel c1 device type disk; restore controlfile from autobackup; } ili restore controlfile from '/oradata3/RMAN_Test/cf_c-1934450637-20080320-03'; (ne treba DBID) za restore je bitno RMAN>SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT'; RMAN>BACKUP ARCHIVELOG ALL;

Restore iz RMAN-a na drugom serveru


- RMAN backupi moraju biti u istom path-u. - Archive logovi prebaeni na novu lokaciju na stanku. Backup napravljen na branku (gdje je i baza), vraen na stanku. Na stanku napravio: export ORACLE_SID=Test

rman:> startup nomount; iz rman backupa-a vratio spfile i control file. Iz spfile-a kreirao pfile i u njemu promijenio path-ove za dump-ove, control file i sl. shutdown pa mount baze. Potebno je preimenovati file-ove koje dobijemo iz restore-a. Sa list backup vidi se koji file-ovi su u backupu. Napravi se: run { set newname for datafile '/oradata2/Test/system01.dbf' to '/oraarh/Test/system01.dbf'; set newname for datafile '/oradata2/Test/undotbs01.dbf' to '/oraarh/Test/undotbs01.dbf'; set newname for datafile '/oradata2/Test/sysaux01.dbf' to '/oraarh/Test/sysaux01.dbf'; set newname for datafile '/oradata2/Test/users01.dbf' to '/oraarh/Test/users01.dbf'; set newname for datafile '/oradata2/Test/podaci01.dbf' to '/oraarh/Test/podaci01.dbf'; set newname for datafile '/oradata2/Test/indeksi01.dbf' to '/oraarh/Test/indeksi01.dbf'; set newname for datafile '/oradata2/Test/orabpel.dbf' to '/oraarh/Test/orabpel.dbf'; restore database; (revover noredo;) nije potrebno switch datafile all; } nakon toga iz sqlplus-a se pokrene recovery: recover database until cancel using backup controlfile; i nakon toga: alter database open resetlogs; i to je to.

v$rman_output backup database plus archivelog; - radi sve, proces najprije radi log switch (koristei alter system archivelog current;). Zatim uzima backup postojeih archive log fileova, potom i baze.Ponovno se napravi log switch i backup-iraju se preostali archive log file-ovi (koristei backup archivelog all naredbu). ---Uzeo backup sa backup database plus archivelog; Napravio restore spfile-a, control file-a (u nomountu), mountao bazu, restore database, recover database i alter database open resetlogs. Sve radi.

RESTORE PRODUKCIJSKE BAZE SA STANKA NA BRANKA


Imao sam RMAN backup baze (bez arhive) i backup spfile-a i controlfile-a Kako se backup nalazi na lokaciji /oracle/RMAN_Dips, istu sam napravio i na branku (soft link prema bilo kojoj lokaciji). Bilo bi dobro pripaziti da backup bude na lokalnom disku a baza na brzom mrenom disku kako bi restore bio to bri. Uzmemo pfile originalne baze (ili bilo koji drugi pfile) i prilagodimo ga novim lokacijama (contorlfile, dump destinacije, flashback destinacija, log_archive...). > export ORACLE_HOME=/oradata2/Oracle10g > export ORACLE_SID=Dips > rman RMAN> connect target; RMAN> stratup nomount; *Ukoliko nemamo originalni pfile, moemo ga dobiti iz backup-a (restore spfile...). Nije trebalo pa vraamo samo contorlfile. RMAN> restore controlfile from '/oracle/RMAN_Dips/cf_c-376567402-20101027-00; RMAN> alter database mount; *Ukoliko nam se razlikuju RMAN lokacije potrebno je katologizirati RMAN backup file (RMAN> catalog backuppiece '/oracle/RMAN_Dips/backup_nulrfdtt_1_1';) nije bilo potrebno jer su lokacije iste. Redo log file-ovi oni se ne restore-aju. Lokacije je razliita pa ih je potrebno preimenovati otvori se SQL.
SQL> alter database rename file '/oradata1/Dips/redo02.log' to /oradata3/Dips/redo02.log'; SQL> alter database rename file '/oradata1/Dips/redo02-2.log' to '/oradata3/Dips/redo02-2.log'; SQL> alter database rename file '/oradata1/Dips/redo03.log' to '/oradata3/Dips/redo03.log'; SQL> alter database rename file '/oradata1/Dips/redo03-3.log' to '/oradata3/Dips/redo03-3.log'; SQL> alter database rename file '/oradata1/Dips/redo04-1.log' to '/oradata3/Dips/redo04-1.log'; SQL> alter database rename file '/oradata1/Dips/redo04-2.log' to '/oradata3/Dips/redo04-2.log'; SQL> alter database rename file '/oradata1/Dips/redo01-1.log' to '/oradata3/Dips/redo01-1.log'; SQL> alter database rename file '/oradata1/Dips/redo01-2.log' to '/oradata3/Dips/redo01-2.log';

S naredbom list backup vidimo sadraj backup-a, odnosno lokacije datafile-ova koje moramo promijeniti. RMAN> list backup; Sad napravimo skriptu za oporavak s promjenom imena fileova: RMAN > run {
set newname for datafile '/oradata1/Dips/undotbs01.dbf' to '/oradata3/Dips/undotbs01.dbf'; set newname for datafile '/oradata1/Dips/system01.dbf' to '/oradata3/Dips/system01.dbf'; set newname for datafile '/oradata1/Dips/indeksi01.dbf' to '/oradata3/Dips/indeksi01.dbf'; set newname for datafile '/oradata1/Dips/sysaux01.dbf' to '/oradata3/Dips/sysaux01.dbf'; set newname for datafile '/oradata1/Dips/users01.dbf' to '/oradata3/Dips/users01.dbf'; set newname for datafile '/oradata1/Dips/example01.dbf' to '/oradata3/Dips/example01.dbf'; set newname for datafile '/oradata1/Dips/podaci01.dbf' to '/oradata3/Dips/podaci01.dbf'; set newname for datafile '/oradata1/Dips/podaci02.dbf' to '/oradata3/Dips/podaci02.dbf'; set newname for datafile '/oradata1/Dips/pod_arh01.dbf' to '/oradata3/Dips/pod_arh01.dbf'; set newname for datafile '/oradata1/Dips/mp2data01.dbf' to '/oradata3/Dips/mp2data01.dbf'; set newname for datafile '/oradata1/Dips/mp2index01.dbf' to '/oradata3/Dips/mp2index01.dbf';

set newname for datafile '/oradata1/Dips/gemmstbl01.dbf' to '/oradata3/Dips/gemmstbl01.dbf'; set newname for datafile '/oradata1/Dips/gemmsind01.dbf' to '/oradata3/Dips/gemmsind01.dbf'; set newname for datafile '/oradata1/Dips/mp2proc01.dbf' to '/oradata3/Dips/mp2proc01.dbf'; set newname for datafile '/oradata1/Dips/mp2proc01.dbf' to '/oradata3/Dips/mp2proc01.dbf'; set newname for datafile '/oradata1/Dips/undo2.dbf' to '/oradata3/Dips/undo2.dbf'; restore database; switch datafile all; }

*Ako ne bi eljeli primjeniti archive log file-ove napravili bi: restore database; i alter database open resetlogs;. Ja sam otvorio sql i pokrenuo opravak uz primjenu archive log file-ova. SQL> recover database until cancel using backup controlfile; Prebacimo potrebne archive log file-ove s backupa ili s originalne lokacije na nau archive log destinaciju (moemo je i promijeniti s alter system...) Kad dosadi ili kad doemo do kraja CANCEL. SQL> alter database open resetlogs; Digresija: Zaboravio sam primjeniti switch datafile all; na kraju restore-a. Ponovno sam pokrenuo RMAN i izveo cijeli set naredbi ali bez restore database;).

RMAN Commands RMAN uses two types of commands: stand-alone and job commands. Generally stand-alone commands are self-contained. Following are some of the standalone commands: Change Connect Create Catalog, Resync Catalog Create Script, Delete Script, Replace Script The job commands are usually grouped and RMAN executes the job commands inside of a run command block sequentially. If any command within the block fails, RMAN ceases processingno further commands within the block are executed.
RMAN> startup mount pfile=/u01/oracle/db01/pfile/initdb01.ora RMAN> shutdown immediate

To List the Current Configuration of the Target Database Use the REPORT command to get the configuration of the database.
RMAN> report schema;

Channel Allocation Each channel usually corresponds to one output device.

REPORT NEED BACKUP Command Lists all data files requiring a backup Assumes most recent backup used during a
restore. Three options are available: Incremental Days Redundancy

report need backup days 3; report need backup days 3; report need backup incremental 3; report need backup incremental 3; report need backup redundancy 3; report need backup redundancy 3;

LIST Command List all copies of data files in the SYSTEM


tablespace:
RMAN > list copy of tablespace SYSTEM;

List all backup sets containing the data file


user01.dbf:
RMAN > list backupset of datafile 2> /disk1/data/user01.dbf;

List incarnation for database DB00:


RMAN > list incarnation of database DB00; RMAN > list incarnation of database DB00;

Using the LIST Command

Before using the LIST command, you must connect to RMAN specifying both the target database and the recovery catalog:
RMAN> target sys/oracle@DB00 \ 2> rcvcat rman/rman@RCVCAT

Stored Scripts A recovery manager script is a set of commands that: Specify frequently used backup, recover, and restore operations Are created using the CREATE SCRIPT command Are stored in the recovery catalog Can be called only within the RUN command Enables you to plan, develop, and test a set of commands for backing up, restoring, and recovering the database Minimize the potential for operator errors.
RMAN> create script Level0Backup { allocate channel d1 type disk; backup incremental level 0 format /u01/db01/backup/%d_%s_%p fileperset 5 (database include current controlfile); sql alter database archive log current; release channel d1;}
RMAN > run {execute script Level0Backup;}

RUN Command
To run an operating system command: RMAN > run { host ls -l; } To run a SQL command: RMAN > run { sql alter system switch logfile;} RMAN > run { sql alter system switch logfile;} To run a stored script: RMAN > run { execute script NightlyBackup;}

How to Create a Recovery Catalog To create the recovery catalog, perform the following steps: 1 Connect to the catalog database and create a tablespace for the catalog:
SQL > create tablespace rman_ts datafile <directory>/<name> > size 20M default storage (initial 100K next 100K pctincrease 0);

2 Create a Recovery Manager user:


SQL > create user rman_db1 identified by rman_db1

2> default tablespace rman_ts 3> temporary tablespace temp 4> quota unlimited on rman_ts;

3 Grant the roles and privileges to this user to maintain the recovery catalog and

perform the backup and recovery operations.


SQL > grant recovery_catalog_owner to rman_db1; SQL > grant connect, resource to rman_db1; 5 Log in to the operating system and run the RMAN command to invoke the RMAN

command interpreter and create the catalog. Use of the MSGLOG (or LOG in Oracle8i) option enables RMAN to output messages and commands to a file.
% rman catalog rman_db1/rman_db1@catdb msglog = catalog.log create catalog tablespace rman_ts; exit;

7 Connect using the RMAN executable on the server containing the target database.

You should log in as a user with SYSDBA privileges on the target database to perform all the backup and recovery operations.
% rman target sys/oracle@db1 Recovery Manager: Release 8.1.5.0.0 - Production RMAN-06005: connected to target database: DB1 (DBID=472633597) RMAN> connect catalog rman_db1/rman_db1@catdb RMAN-06008: connected to recovery catalog database

8 Register the target database in the catalog. If the target database is not registered in

the recovery catalog, the catalog may not be used to store information about the database. Recovery Manager uses the internal database identifier (DBID), which is calculated when the database is first created, as a unique identifier for the database. If you attempt to register a new database that has been created by copying an existing database and then changing the db_name, the register will fail. To back up a copied database, create a new recovery catalog owner, and create the catalog in the new account
RMAN> register database; RMAN-03022: compiling command: register RMAN-03023: executing command: register RMAN-08006: database registered in recovery catalog RMAN-03023: executing command: full resync RMAN-08002: starting full resync of recovery catalog RMAN-08004: full resync complete RMAN> Resync the catalog with target: Add or drop a tablespace Add or drop a data file Add or drop a rollback segment Relocate any database file $ rman target scott/tiger@db01 catalog rman/rman@catdb RMAN > resync catalog;

Catalog command
Use the CATALOG command to add information to the catalog When backup is taken using OS When backup is taken without recovery catalog The CATALOG command stores: Archived logs, data file copies, and control file copies

that belong to the target database Only files with the same database incarnation number RMAN > catalog datafilecopy /u01/db1/backup/system01.bak 2 > tag = SYSTBS0429; RMAN > catalog archivelog 2>/u01/db1/ARCHIVE/arch_267.log;

S-ar putea să vă placă și