wtorek, 2 czerwca 2015

Podstawowe skrypty backup i restore

------------- Skrypt BACKUP kopia bazy

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
RUN {
ALLOCATE CHANNEL SQLDEV_DISK_BACKUP DEVICE TYPE DISK;
RECOVER COPY OF DATABASE WITH TAG 'ORA_SQLDEV_LEVEL_0';
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE COPIES=1 FOR RECOVER OF COPY WITH TAG 'ORA_SQLDEV_LEVEL_0' DATABASE;
}
ALTER DATABASE OPEN;

--------------Skrypt RESTORE odtworzenie bazy

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
RUN {
RESTORE DATABASE UNTIL TIME "TO_DATE('2014-06-01 18:18:57', 'YYYY-MM-DD HH24:MI:SS')";
}
ALTER DATABASE OPEN RESETLOGS;


---------------Skrypt RESTORE datafiles

RUN {
RESTORE DATAFILE  UNTIL TIME "TO_DATE('2014-06-01 18:21:02', 'YYYY-MM-DD HH24:MI:SS')";
}


---------------Skrypt RESTORE tablespace

RUN {
RESTORE TABLESPACE  UNTIL TIME "TO_DATE('2014-06-01 18:23:42', 'YYYY-MM-DD HH24:MI:SS')";
}


-------------Przyklad restore




This operation will shut down and restore the database. Are you sure [Y/N]?y
Restore in progress...
Żądana usługa została już uruchomiona.

Dostępne są dalsze informacje Pomocy; aby je uzyskać, wpisz NET HELPMSG 2182.


Recovery Manager: Release 11.2.0.2.0 - Production on îr Gru 25 13:59:59 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: XE (DBID=274236787)

RMAN> set echo on;
2> startup nomount pfile=C:\Users\admin\AppData\Local\Temp\rman_dummy.ora force;

3>
echo set on

Oracle instance started

Total System Global Area     284565504 bytes

Fixed Size                     1383076 bytes
Variable Size                100664668 bytes
Database Buffers             176160768 bytes
Redo Buffers                   6356992 bytes

Recovery Manager complete.
Recovery Manager: Release 11.2.0.2.0 - Production on îr Gru 25 14:00:29 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: XE (not mounted)

RMAN> set echo on;
2> shutdown immediate;
3> startup nomount pfile="C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\
SPFILE2INIT.ORA";
4> restore (spfile from autobackup) (controlfile from autobackup);
5> startup mount force;
6> configure controlfile autobackup off;
7> restore database;
8>
echo set on

using target database control file instead of recovery catalog
Oracle instance shut down

connected to target database (not started)
Oracle instance started

Total System Global Area     376635392 bytes

Fixed Size                     1383692 bytes
Variable Size                289407732 bytes
Database Buffers              79691776 bytes
Redo Buffers                   6152192 bytes

Starting restore at 13/12/25
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

recovery area destination: C:\oraclexe\app\oracle\fast_recovery_area
database name (or database unique name) used for search: XE
channel ORA_DISK_1: AUTOBACKUP C:\ORACLEXE\APP\ORACLE\FAST_RECOVERY_AREA\XE\AUTO
BACKUP\2013_12_25\O1_MF_S_835106118_9COOLFW3_.BKP found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring spfile from AUTOBACKUP C:\ORACLEXE\APP\ORACLE\FAST
_RECOVERY_AREA\XE\AUTOBACKUP\2013_12_25\O1_MF_S_835106118_9COOLFW3_.BKP
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
failover to previous backup

recovery area destination: C:\oraclexe\app\oracle\fast_recovery_area
database name (or database unique name) used for search: XE
channel ORA_DISK_1: AUTOBACKUP C:\ORACLEXE\APP\ORACLE\FAST_RECOVERY_AREA\XE\AUTO
BACKUP\2013_12_25\O1_MF_S_835106118_9COOLFW3_.BKP found in the recovery area
AUTOBACKUP search with format "%F" not attempted because DBID was not set
channel ORA_DISK_1: restoring control file from AUTOBACKUP C:\ORACLEXE\APP\ORACL
E\FAST_RECOVERY_AREA\XE\AUTOBACKUP\2013_12_25\O1_MF_S_835106118_9COOLFW3_.BKP
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=C:\ORACLEXE\APP\ORACLE\ORADATA\XE\CONTROL.DBF
Finished restore at 13/12/25

Oracle instance started
database mounted

Total System Global Area     376635392 bytes

Fixed Size                     1383692 bytes
Variable Size                289407732 bytes
Database Buffers              79691776 bytes
Redo Buffers                   6152192 bytes

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored

Starting restore at 13/12/25
Starting implicit crosscheck backup at 13/12/25
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 13/12/25

Starting implicit crosscheck copy at 13/12/25
using channel ORA_DISK_1
Finished implicit crosscheck copy at 13/12/25

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: C:\ORACLEXE\APP\ORACLE\FAST_RECOVERY_AREA\XE\AUTOBACKUP\2013_12_25\O1
_MF_S_835106118_9COOLFW3_.BKP

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to C:\ORACLEXE\APP\ORACLE\ORADATA\X
E\SYSTEM.DBF
channel ORA_DISK_1: restoring datafile 00002 to C:\ORACLEXE\APP\ORACLE\ORADATA\X
E\UNDOTBS1.DBF
channel ORA_DISK_1: restoring datafile 00003 to C:\ORACLEXE\APP\ORACLE\ORADATA\X
E\SYSAUX.DBF
channel ORA_DISK_1: restoring datafile 00004 to C:\ORACLEXE\APP\ORACLE\ORADATA\X
E\USERS.DBF
channel ORA_DISK_1: reading from backup piece C:\ORACLEXE\APP\ORACLE\FAST_RECOVE
RY_AREA\XE\BACKUPSET\2013_12_25\O1_MF_NNNDF_TAG20131225T135543_9COOGJOP_.BKP
channel ORA_DISK_1: piece handle=C:\ORACLEXE\APP\ORACLE\FAST_RECOVERY_AREA\XE\BA
CKUPSET\2013_12_25\O1_MF_NNNDF_TAG20131225T135543_9COOGJOP_.BKP tag=TAG20131225T
135543
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:57
Finished restore at 13/12/25

Recovery Manager complete.
Recovery Manager: Release 11.2.0.2.0 - Production on îr Gru 25 14:02:41 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: XE (DBID=2712327699, not open)

RMAN> set echo on;
2> alter database open resetlogs;
3>
echo set on

using target database control file instead of recovery catalog
database opened

Recovery Manager complete.
Restore of the database succeeded.
Log file is at C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\OXE_RESTORE
.LOG.