国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Oracle12c RMAN基于表的時間點恢復

IT那活兒 / 2804人閱讀
Oracle12c RMAN基于表的時間點恢復
點擊上方“IT那活兒”公眾號,關注后了解更多內容,不管IT什么活兒,干就完了!!!
1

概念

在Oracle數據庫中,對于用戶DDL(DROP TRUNCATE)等誤操作,引起的數據丟失,恢復的手段有:

  • 基于數據庫時間點不完全恢復;
  • 基于表空間時間點恢復TSPIRT進行數據恢復。
但是在12c中,RMAN新的特性:基于表的時間點恢復,更加方便。
如下圖官方文檔所示:

2

恢復的目的

12c的RMAN基于表級別恢復是可以恢復單個或者更多的表或者分區表的時候,而不影響其他的數據庫對象,就是說在11g你無法基于表級別恢復,而當你做基于時間點恢復,那么數據庫上的其他對象也會恢復到你要恢復的那個時間點,或者你做基于表空間的恢復(TSPITR)都是會影響其他的數據庫對象。
在 Oracle 12c 中,在發生 drop truncate 的情況下,可以從 RMAN 備份中將一個特定的表或分區恢復到某個時間點、SCN 或歸檔序列號。

如果是 delete 的誤操作,如果在閃回范圍時間內,可以用閃回來恢復。

3

恢復的要求

如官方文檔所示:
--主要用到的技術:
Oracle 12c的Recover Table新特性是利用創建輔助臨時實例加數據泵工具來實現的。
通常在進行Recover Table之前應該準備好兩個目錄(AUXILIARY DESTINATION和DATAPUMP DESTINATION),AUXILIARY DESTINATION用來臨時存放輔助實例的數據文件,DATAPUMP DESTINATION用來臨時存放數據泵導出的文件。

--步驟

  • 建立一個輔助的實例;
  • 在輔助實例上做全庫的恢復;
  • 通過datapump工具導出,導入。

4

恢復實驗過程

4.1 創建測試用戶,授權,分配測試表空間,給測試數據
--創建測試用戶:
SQL> alter session set container=PRODPDB;

Session altered.

SQL>

SQL> show con_name;

CON_NAME
------------------------------
PRODPDB

SQL>
 create user pdbwjh identified by pdbwjh;

User created.
--授權:
grant connect,resource to pdbwjh;
grant CREATE TABLE to pdbwjh;
grant SELECT ANY TABLE to pdbwjh;
grant UNLIMITED TABLESPACE to pdbwjh;
--創建測試表空間,并更改用戶表空間。
--創建數據tbs:
create tablespace pdbwjh_data logging datafile /u01/app/oracle/oradata/prod/prodpdb/pdbwjh_data01.dbf size 100M autoextend off;
--創建臨時tbs:
create temporary tablespace pdbwjh_temp tempfile /u01/app/oracle/oradata/prod/prodpdb/pdbwjh_tmp.dbf size 30M autoextend off;
--更改用戶默認表空間:
alter user pdbwjh default tablespace pdbwjh_data temporary tablespace pdbwjh_temp;
--查詢用戶所在表空間:
set line 300;
col username for a20
select USERNAME,ACCOUNT_STATUS,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE from dba_users where username=&username;



USERNAME ACCOUNT_STATUS DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
-------------------- -------------------------------- ------------------------------ ------------------------------
PDBWJH OPEN PDBWJH_DATA PDBWJH_TEMP
--創表給數據:
SQL> create table PDBWJH.testjk tablespace PDBWJH_DATA as select * from dba_objects;
Table created.
SQL>
SQL> select count(1) from pdbwjh.testjk;
COUNT(1)
----------
72635
SQL> commit;
Commit complete.
4.2 對數據庫進行backup,因為恢復需要提前有備份集才可以
[oracle@12c ~]$ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Wed Jun 29 23:19:33 2022

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

connected to target database: PROD (DBID=515416371)

RMAN> run{
crosscheck archivelog all;
crosscheck backup;
backup database ;
backup archivelog all delete all input ;
backup current controlfile;
}2> 3> 4> 5> 6> 7>

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=278 device type=DISK
specification does not match any archived log in the repository

using channel ORA_DISK_1
specification does not match any backup in the repository

Starting backup at 29-JUN-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/prod/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/prod/undotbs01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkpbl_.bkp tag=TAG20220629T232230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/prod/prodpdb/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/prod/prodpdb/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/prod/prodpdb/undotbs01.dbf
input datafile file number=00020 name=/u01/app/oracle/oradata/prod/prodpdb/pdbwjh_data01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/prod/prodpdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/DDF44DDF02C79B34E053C82BA8C0429E/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkxgh_.bkp tag=TAG20220629T232230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/u01/app/oracle/oradata/prod/prodpdb1/sysaux01.dbf
input datafile file number=00016 name=/u01/app/oracle/oradata/prod/prodpdb1/system01.dbf
input datafile file number=00018 name=/u01/app/oracle/oradata/prod/prodpdb1/undotbs01.dbf
input datafile file number=00021 name=/u01/app/oracle/oradata/prod/prodpdb1/tbs1.dbf
input datafile file number=00019 name=/u01/app/oracle/oradata/prod/prodpdb1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/DE31ABD04811453BE053C800A8C01835/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvl0l7_.bkp tag=TAG20220629T232230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/prod/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/prod/pdbseed/system01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/prod/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/DDF43DBAEC79939EE053C82BA8C00C8C/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvl3o0_.bkp tag=TAG20220629T232230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 29-JUN-22

Starting backup at 29-JUN-22
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=17 RECID=13 STAMP=1108682566
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_annnn_TAG20220629T232247_kcrvl73l_.bkp tag=TAG20220629T232247 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/prod/PROD/archivelog/2022_06_29/o1_mf_1_17_kcrvl6z4_.arc RECID=13 STAMP=1108682566
Finished backup at 29-JUN-22

Starting backup at 29-JUN-22
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 29-JUN-22
channel ORA_DISK_1: finished piece 1 at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_ncnnf_TAG20220629T232248_kcrvl9hy_.bkp tag=TAG20220629T232248 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-JUN-22

Starting Control File and SPFILE Autobackup at 29-JUN-22
piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/autobackup/2022_06_29/o1_mf_s_1108682570_kcrvlbmq_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 29-JUN-22
4.3 模擬用戶誤刪除表(truncate,無法使用閃回)
[oracle@12c ~]$ sqlplus pdbwjh/pdbwjh@prodpdb

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jun 29 23:26:35 2022

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Last Successful login time: Tue Jun 28 2022 21:55:38 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>

SQL>
SQL> show con_name

CON_NAME
------------------------------
PRODPDB
SQL> select table_name from user_tables;

TABLE_NAME
--------------------------------------------------------------------------------
SQLLOADER_TEST01
TESTJK

SQL>
 select count(1) from testjk;

COUNT(1)
----------
72635
SQL>
SQL> truncate table testjk;

Table truncated.

SQL>
 alter session set nls_date_format=yyyy-mm-dd hh24:mi:ss;

Session altered.
--發現誤刪除后,趕快確認當前的系統時間:
SQL>
SQL> select sysdate from dual;

SYSDATE
-------------------
2022-06-29 23:29:17
這里需要drop掉,不然恢復的時候,是會報錯說表存在:
SQL> drop table testjk;

Table dropped.
4.4 創建輔助實例的位置AUXILIARY destination /u01/tsbakdatapump destination /u01/dump的路徑
[oracle@12c u01]$ mkdir tsbak
[oracle@12c u01]$ mkdir dump
[oracle@12c u01]$ ls -l
總用量 0
drwxrwxr-x. 4 oracle oinstall 40 427 23:00 app
drwxr-xr-x 2 oracle oinstall 6 525 21:00 arch
drwxr-xr-x 7 oracle oinstall 117 127 2017 database
drwxr-xr-x 2 oracle oinstall 6 628 21:55 dump
drwxr-xr-x 2 oracle oinstall 6 629 23:34 tsbak
4.5 登錄RMAN工具,使用RMAN進行恢復
注:紅色文字部分為批注。
RMAN> RECOVER TABLE pdbwjh.testjk of pluggable database prodpdb 恢復的語句,指定表所在的pdb
until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)"
AUXILIARY destination /u01/tsbak
datapump destination /u01/dump;2> 3> 4>

Starting recover at 29-JUN-22
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=280 device type=DISK
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace PRODPDB:SYSTEM
Tablespace UNDOTBS1
Tablespace PRODPDB:UNDOTBS1

Creating automatic instance, with SID=qsbb 創建了輔助實例,實例的SID為 qsbb

initialization parameters used for automatic instance:
db_name=PROD
db_unique_name=qsbb_pitr_prodpdb_PROD
compatible=12.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/app/oracle
_system_trig_enabled=FALSE
sga_target=1520M
processes=200
db_create_file_dest=/u01/tsbak 我指定的輔助實例存儲的位置
log_archive_dest_1=location=/u01/tsbak
enable_pluggable_database=true 是否是PDB,因為我恢復的是PDB里面的表的數據,所以這里是true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance PROD

Oracle instance started

Total System Global Area 1593835520 bytes

Fixed Size 8793256 bytes
Variable Size 402654040 bytes
Database Buffers 1174405120 bytes
Redo Buffers 7983104 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)"; 指定恢復的時間點,也可以指定SCN
# restore the controlfile
restore clone controlfile;

# mount the controlfile
sql clone alter database mount clone database;

# archive current online log
sql alter system archive log current;
}
executing Memory Script

executing command: SET until clause

Starting restore at 29-JUN-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=180 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/autobackup/2022_06_29/o1_mf_s_1108682570_kcrvlbmq_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/autobackup/2022_06_29/o1_mf_s_1108682570_kcrvlbmq_.bkp tag=TAG20220629T232250
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/tsbak/PROD/controlfile/o1_mf_kcrwtxq4_.ctl
Finished restore at 29-JUN-22

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 9 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 11 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 10 to new;
set newname for clone tempfile 1 to new;
set newname for clone tempfile 3 to new;
set newname for clone tempfile 5 to new;
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 9, 4, 11, 3, 10;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME
renamed tempfile 1 to /u01/tsbak/PROD/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 5 to /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_pdbwjh_t_%u_.tmp in control file

Starting restore at 29-JUN-22
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore 備份需要恢復的數據文件,可以理解為將備份集copy到輔助實例目錄下
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/tsbak/PROD/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/tsbak/PROD/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/tsbak/PROD/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkpbl_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkpbl_.bkp tag=TAG20220629T232230
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/DDF44DDF02C79B34E053C82BA8C0429E/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkxgh_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/DDF44DDF02C79B34E053C82BA8C0429E/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkxgh_.bkp tag=TAG20220629T232230
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 29-JUN-22

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=1108683881 file name=/u01/tsbak/PROD/datafile/o1_mf_system_kcrwv3g8_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=11 STAMP=1108683881 file name=/u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_system_kcrwv6kh_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=1108683881 file name=/u01/tsbak/PROD/datafile/o1_mf_undotbs1_kcrwv3gb_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=13 STAMP=1108683881 file name=/u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_undotbs1_kcrwv6kh_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=1108683881 file name=/u01/tsbak/PROD/datafile/o1_mf_sysaux_kcrwv3gb_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=15 STAMP=1108683881 file name=/u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_sysaux_kcrwv6kg_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)";
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone PRODPDB "alter database datafile
9 online"
;
sql clone "alter database datafile 4 online";
sql clone PRODPDB "alter database datafile
11 online"
;
sql clone "alter database datafile 3 online";
sql clone PRODPDB "alter database datafile
10 online"
;
# recover and open database read only
recover clone database tablespace "SYSTEM", "PRODPDB":"SYSTEM", "UNDOTBS1", "PRODPDB":"UNDOTBS1", "SYSAUX", "PRODPDB":"SYSAUX";
sql clone alter database open read only;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile 1 online

sql statement: alter database datafile 9 online

sql statement: alter database datafile 4 online

sql statement: alter database datafile 11 online

sql statement: alter database datafile 3 online

sql statement: alter database datafile 10 online

Starting recover at 29-JUN-22
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 18 is already on disk as file /u01/app/oracle/fast_recovery_area/prod/PROD/archivelog/2022_06_29/o1_mf_1_18_kcrwcofv_.arc
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_annnn_TAG20220629T232247_kcrvl73l_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_annnn_TAG20220629T232247_kcrvl73l_.bkp tag=TAG20220629T232247
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/tsbak/1_17_1103578037.dbf thread=1 sequence=17
archived log file name=/u01/app/oracle/fast_recovery_area/prod/PROD/archivelog/2022_06_29/o1_mf_1_18_kcrwcofv_.arc thread=1 sequence=18
media recovery complete, elapsed time: 00:00:00
Finished recover at 29-JUN-22

sql statement: alter database open read only

contents of Memory Script:
{
sql clone alter pluggable database PRODPDB open read only;
}
executing Memory Script

sql statement: alter pluggable database PRODPDB open read only

contents of Memory Script:
{
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
/u01/tsbak/PROD/controlfile/o1_mf_kcrwtxq4_.ctl comment=
RMAN set scope=spfile"
;
shutdown clone immediate;
startup clone nomount;
# mount database
sql clone alter database mount clone database;
}
executing Memory Script

sql statement: create spfile from memory

database closed
database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 1593835520 bytes

Fixed Size 8793256 bytes
Variable Size 402654040 bytes
Database Buffers 1174405120 bytes
Redo Buffers 7983104 bytes

sql statement: alter system set  control_files = /u01/tsbak/PROD/controlfile/o1_mf_kcrwtxq4_.ctl comment= RMAN set scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 1593835520 bytes

Fixed Size 8793256 bytes
Variable Size 402654040 bytes
Database Buffers 1174405120 bytes
Redo Buffers 7983104 bytes

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile 20 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 20;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

Starting restore at 29-JUN-22
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=162 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore 從備份集中進行restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00020 to /u01/tsbak/QSBB_PITR_PRODPDB_PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_pdbwjh_d_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/DDF44DDF02C79B34E053C82BA8C0429E/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkxgh_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/DDF44DDF02C79B34E053C82BA8C0429E/backupset/2022_06_29/o1_mf_nnndf_TAG20220629T232230_kcrvkxgh_.bkp tag=TAG20220629T232230
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 29-JUN-22

datafile 20 switched to datafile copy
input datafile copy RECID=17 STAMP=1108683941 file name=/u01/tsbak/QSBB_PITR_PRODPDB_PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_pdbwjh_d_kcrwx4ck_.dbf

contents of Memory Script:
{
# set requested point in time
set until time "to_date(2022-06-29 23:28:00,yyyy-mm-dd hh24:mi:ss)";
# online the datafiles restored or switched
sql clone PRODPDB "alter database datafile
20 online"
;
# recover and open resetlogs reostore后,進行recover
recover clone database tablespace "PRODPDB":"PDBWJH_DATA", "SYSTEM", "PRODPDB":"SYSTEM", "UNDOTBS1", "PRODPDB":"UNDOTBS1", "SYSAUX", "PRODPDB":"SYSAUX" delete archivelog;
alter clone database open resetlogs; recover后,resetlogs打開數據庫實例
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile 20 online

Starting recover at 29-JUN-22
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 18 is already on disk as file /u01/app/oracle/fast_recovery_area/prod/PROD/archivelog/2022_06_29/o1_mf_1_18_kcrwcofv_.arc
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_annnn_TAG20220629T232247_kcrvl73l_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/prod/PROD/backupset/2022_06_29/o1_mf_annnn_TAG20220629T232247_kcrvl73l_.bkp tag=TAG20220629T232247
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/tsbak/1_17_1103578037.dbf thread=1 sequence=17
channel clone_default: deleting archived log(s)
archived log file name=/u01/tsbak/1_17_1103578037.dbf RECID=15 STAMP=1108683942
archived log file name=/u01/app/oracle/fast_recovery_area/prod/PROD/archivelog/2022_06_29/o1_mf_1_18_kcrwcofv_.arc thread=1 sequence=18
media recovery complete, elapsed time: 00:00:01
Finished recover at 29-JUN-22

database opened

contents of Memory Script:
{
sql clone alter pluggable database PRODPDB open;
}
executing Memory Script

sql statement: alter pluggable database PRODPDB open

contents of Memory Script:
{
# create directory for datapump import
sql PRODPDB "create or replace directory
TSPITR_DIROBJ_DPDIR as
/u01/dump"
;
# create directory for datapump export
sql clone PRODPDB "create or replace directory
TSPITR_DIROBJ_DPDIR as
/u01/dump"
;
}
executing Memory Script

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as /u01/dump    輔助實例恢復完后,將輔助實例中的數據文件以dump形式導出來,然后在導入到我們的pdb

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as /u01/dump     創建directory

Performing export of tables...
EXPDP> Starting "SYS"."TSPITR_EXP_qsbb_lgbr":
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
EXPDP> . . exported "PDBWJH"."TESTJK"                           9.614 MB 72635 rows 導出數據
EXPDP> Master table "SYS"."TSPITR_EXP_qsbb_lgbr" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_qsbb_lgbr is:
EXPDP> /u01/dump/tspitr_qsbb_93806.dmp dump存放的路徑
EXPDP> Job "SYS"."TSPITR_EXP_qsbb_lgbr" successfully completed at Wed Jun 29 23:46:20 2022 elapsed 0 00:00:16
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
}
executing Memory Script

Oracle instance shut down

Performing import of tables...
IMPDP> Master table "SYS"."TSPITR_IMP_qsbb_feFA" successfully loaded/unloaded 導入到我們所需恢復的實例Pdb中
IMPDP> Starting "SYS"."TSPITR_IMP_qsbb_feFA":
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE
IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
IMPDP> . . imported "PDBWJH"."TESTJK"                           9.614 MB 72635 rows
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
IMPDP> Job "SYS"."TSPITR_IMP_qsbb_feFA" successfully completed at Wed Jun 29 23:46:38 2022 elapsed 0 00:00:12
Import completed


Removing automatic instance 導入成功后,輔助實例上的數據文件等都會被刪除
Automatic instance removed
auxiliary instance file /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_pdbwjh_t_kcrwvh18_.tmp deleted
auxiliary instance file /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_temp_kcrwvh0v_.tmp deleted
auxiliary instance file /u01/tsbak/PROD/datafile/o1_mf_temp_kcrwvf5y_.tmp deleted
auxiliary instance file /u01/tsbak/QSBB_PITR_PRODPDB_PROD/onlinelog/o1_mf_3_kcrwx85l_.log deleted
auxiliary instance file /u01/tsbak/QSBB_PITR_PRODPDB_PROD/onlinelog/o1_mf_2_kcrwx84h_.log deleted
auxiliary instance file /u01/tsbak/QSBB_PITR_PRODPDB_PROD/onlinelog/o1_mf_1_kcrwx83w_.log deleted
auxiliary instance file /u01/tsbak/QSBB_PITR_PRODPDB_PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_pdbwjh_d_kcrwx4ck_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_sysaux_kcrwv6kg_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/datafile/o1_mf_sysaux_kcrwv3gb_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_undotbs1_kcrwv6kh_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/datafile/o1_mf_undotbs1_kcrwv3gb_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/DDF44DDF02C79B34E053C82BA8C0429E/datafile/o1_mf_system_kcrwv6kh_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/datafile/o1_mf_system_kcrwv3g8_.dbf deleted
auxiliary instance file /u01/tsbak/PROD/controlfile/o1_mf_kcrwtxq4_.ctl deleted
auxiliary instance file tspitr_qsbb_93806.dmp deleted
Finished recover at 29-JUN-22

RMAN>
--恢復完畢后,查看數據庫數據:
[oracle@12c ~]$ sqlplus pdbwjh/pdbwjh@prodpdb

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jun 29 23:46:54 2022

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Last Successful login time: Wed Jun 29 2022 23:26:35 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>

SQL>
SQL>
SQL> select table_name from user_tables;

TABLE_NAME
--------------------------------------------------------------------------------
SQLLOADER_TEST01
TESTJK

SQL>
 select count(1) from testjk;

COUNT(1)
----------
72635

--數據表已恢復。

5

總結

需要注意的是:
  • 需要恢復的數據庫必須是歸檔模式;
  • 數據庫屬于讀寫模式;
  • 確保需要恢復的輔助實例所創建的目錄位置要有足夠的大小,否則恢復會報錯;
  • 如果是恢復PDB中的單個表,需要指定。

本文作者:王俊暉(上海新炬王翦團隊)

本文來源:“IT那活兒”公眾號

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129352.html

相關文章

  • Windows平臺下Oracle數據庫備份腳本

    摘要:以下腳本是我在項目工作中使用的備份腳本,腳本都是自己寫的。簡介此套腳本可以實現對數據庫實現全備份和增量備份。綜合以上兩種利弊,比較好的方式是在出現丟失備份或的情況下,通知管理員處置,手工處理之后備份腳本運行恢復正常。 以下腳本是我在項目工作中使用的備份腳本,腳本都是自己寫的。但在使用過程中,感覺還有提供空間,我這個人有點懶,所以想用將腳本開源出來的方式督促自己完善這一套腳本。大家如果對...

    tomorrowwu 評論0 收藏0

發表評論

0條評論

IT那活兒

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<