rman備份恢復命令之switch

一 switch 命令
1 switch命令用途
更新數據文件名為rman下鏡像拷貝時指定的數據文件名
更新數據文件名為 set newname 命令指定的名字。
?
2 switch 命令使用前提條件
rman 必須連接到目標數據庫
當switch tablespaces、datafiles、tempfiles時,這些文件必須離線
當switch 整個數據庫時,數據庫不能open

3 注意事項
switch....to copy 命令用于rman命令提示符下
switch沒有to copy的命令用于run語句塊中
??
4 語法
? 第一組
?? switch dtabase to copy;??????????????????
?? switch datafile number|name to copy;
?? switch tablespace name to copy;
? 第二組
?? switch datafile all;
?? switch datafile number|name;
?? switch tempfile all;
???
二 舉例如下:

例一:用switch datafile number to copy 更新數據文件位置和名字
RMAN> backup as copy datafile 8? format '/oracle/CRM/test.dbf';

Starting backup at 2013-02-22 10:06:21
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile copy
input datafile file number=00008 name=/backup/test.dbf
output file name=/oracle/CRM/test.dbf tag=TAG20130222T100621 RECID=14 STAMP=808049181
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2013-02-22 10:06:22

Starting Control File and SPFILE Autobackup at 2013-02-22 10:06:22
piece handle=/backup/c-3599153036-20130222-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2013-02-22 10:06:25


RMAN> sql 'alter tablespace test offline';

sql statement: alter tablespace test offline

RMAN> switch datafile 8 to copy;

datafile 8 switched to datafile copy "/oracle/CRM/test.dbf"


RMAN> report schema;

Report of database schema for database with db_unique_name CRM

List of Permanent Datafiles
===========================
File Size(MB) Tablespace?????????? RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1??? 750????? SYSTEM?????????????? ***???? /oracle/CRM/system01.dbf
2??? 540????? SYSAUX?????????????? ***???? /oracle/CRM/sysaux01.dbf
3??? 100????? UNDOTBS3???????????? ***???? /oracle/CRM/undotbs3.dbf
4??? 1742???? USERS??????????????? ***???? /backup/users01.dbf
5??? 500????? POS????????????????? ***???? /oracle/CRM/pos.dbf
6??? 100????? ERP????????????????? ***???? /oracle/CRM/erp.dbf
7??? 5??????? USER01?????????????? ***???? /oracle/CRM/user01.dbf
8??? 0??????? TEST???????????????? ***???? /oracle/CRM/test.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace?????????? Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1??? 218????? TEMP???????????????? 32767?????? /oracle/CRM/temp01.dbf
2??? 3072???? MYNEWTEMP??????????? 40960?????? /oracle/CRM/newtemp.dbf


例二 用switch tablespace name to copy更新表空間所有數據文件位置和名字
RMAN> backup? as copy? tablespace? pos format '/oracle/%N%f.dbf';
(%N為表空間名、%f為數據文件絕對文件號)
Starting backup at 2013-02-22 10:55:49
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/oracle/CRM/pos.dbf
channel ORA_DISK_2: starting datafile copy
input datafile file number=00009 name=/oracle/CRM/pos2.dbf
output file name=/oracle/POS9.dbf tag=TAG20130222T105549 RECID=18 STAMP=808052153
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:07
output file name=/oracle/POS5.dbf tag=TAG20130222T105549 RECID=19 STAMP=808052179
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:36
Finished backup at 2013-02-22 10:56:25

Starting Control File and SPFILE Autobackup at 2013-02-22 10:56:25
piece handle=/backup/c-3599153036-20130222-03 comment=NONE
Finished Control File and SPFILE Autobackup at 2013-02-22 10:56:28

RMAN> sql 'alter tablespace? pos offline';

sql statement: alter tablespace? pos offline

RMAN> switch tablespace pos to copy;

datafile 5 switched to datafile copy "/oracle/POS5.dbf"
datafile 9 switched to datafile copy "/oracle/POS9.dbf"

RMAN> report schema;

Report of database schema for database with db_unique_name CRM

List of Permanent Datafiles
===========================
File Size(MB) Tablespace?????????? RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1??? 750????? SYSTEM?????????????? ***???? /oracle/CRM/system01.dbf
2??? 540????? SYSAUX?????????????? ***???? /oracle/CRM/sysaux01.dbf
3??? 100????? UNDOTBS3???????????? ***???? /oracle/CRM/undotbs3.dbf
4??? 1742???? USERS??????????????? ***???? /backup/users01.dbf
5??? 0??????? POS????????????????? ***???? /oracle/POS5.dbf
6??? 100????? ERP????????????????? ***???? /oracle/CRM/erp.dbf
7??? 5??????? USER01?????????????? ***???? /oracle/CRM/user01.dbf
8??? 0??????? TEST???????????????? ***???? /oracle/CRM/test.dbf
9??? 0??????? POS????????????????? ***???? /oracle/POS9.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace?????????? Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1??? 218????? TEMP???????????????? 32767?????? /oracle/CRM/temp01.dbf
2??? 3072???? MYNEWTEMP??????????? 40960?????? /oracle/CRM/newtemp.dbf

例三 用switch dtabase to copy更新數據庫所有數據文件位置和名字
RMAN> backup as copy database format '/oracle/CRM/test/%N%f.dbf';

Starting backup at 2013-02-22 11:26:52
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=192 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/backup/users01.dbf
channel ORA_DISK_2: starting datafile copy
input datafile file number=00001 name=/oracle/CRM/system01.dbf
output file name=/oracle/CRM/test/SYSTEM1.dbf tag=TAG20130222T112653 RECID=52 STAMP=808054107
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:01:41
channel ORA_DISK_2: starting datafile copy
input datafile file number=00002 name=/oracle/CRM/sysaux01.dbf
output file name=/oracle/CRM/test/USERS4.dbf tag=TAG20130222T112653 RECID=53 STAMP=808054182
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:02:54
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/oracle/POS5.dbf
output file name=/oracle/CRM/test/SYSAUX2.dbf tag=TAG20130222T112653 RECID=54 STAMP=808054193
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:01:11
channel ORA_DISK_2: starting datafile copy
input datafile file number=00003 name=/oracle/CRM/undotbs3.dbf
output file name=/oracle/CRM/test/UNDOTBS33.dbf tag=TAG20130222T112653 RECID=55 STAMP=808054203
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_2: starting datafile copy
input datafile file number=00006 name=/oracle/CRM/erp.dbf
output file name=/oracle/CRM/test/ERP6.dbf tag=TAG20130222T112653 RECID=56 STAMP=808054230
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_2: starting datafile copy
input datafile file number=00009 name=/oracle/POS9.dbf
output file name=/oracle/CRM/test/POS5.dbf tag=TAG20130222T112653 RECID=57 STAMP=808054247
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:58
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/oracle/CRM/user01.dbf
output file name=/oracle/CRM/test/POS9.dbf tag=TAG20130222T112653 RECID=58 STAMP=808054247
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:08
channel ORA_DISK_2: starting datafile copy
input datafile file number=00008 name=/oracle/CRM/test.dbf
output file name=/oracle/CRM/test/USER017.dbf tag=TAG20130222T112653 RECID=59 STAMP=808054250
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:00
output file name=/oracle/CRM/test/TEST8.dbf tag=TAG20130222T112653 RECID=60 STAMP=808054250
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2013-02-22 11:30:51

Starting Control File and SPFILE Autobackup at 2013-02-22 11:30:51
piece handle=/backup/c-3599153036-20130222-06 comment=NONE
Finished Control File and SPFILE Autobackup at 2013-02-22 11:30:59

RMAN> switch database to copy;

datafile 1 switched to datafile copy "/oracle/CRM/test/SYSTEM1.dbf"
datafile 2 switched to datafile copy "/oracle/CRM/test/SYSAUX2.dbf"
datafile 3 switched to datafile copy "/oracle/CRM/test/UNDOTBS33.dbf"
datafile 4 switched to datafile copy "/oracle/CRM/test/USERS4.dbf"
datafile 5 switched to datafile copy "/oracle/CRM/test/POS5.dbf"
datafile 6 switched to datafile copy "/oracle/CRM/test/ERP6.dbf"
datafile 7 switched to datafile copy "/oracle/CRM/test/USER017.dbf"
datafile 8 switched to datafile copy "/oracle/CRM/test/TEST8.dbf"
datafile 9 switched to datafile copy "/oracle/CRM/test/POS9.dbf"

RMAN> sql 'alter database open';

sql statement: alter database open

SQL> select file#,name,status from v$datafile;

???? FILE# NAME???????????????????????????????????? STATUS
---------- ---------------------------------------- -------
???????? 1 /oracle/CRM/test/SYSTEM1.dbf???????????? SYSTEM
???????? 2 /oracle/CRM/test/SYSAUX2.dbf???????????? ONLINE
???????? 3 /oracle/CRM/test/UNDOTBS33.dbf?????????? ONLINE
???????? 4 /oracle/CRM/test/USERS4.dbf????????????? ONLINE
???????? 5 /oracle/CRM/test/POS5.dbf??????????????? ONLINE
???????? 6 /oracle/CRM/test/ERP6.dbf??????????????? ONLINE
???????? 7 /oracle/CRM/test/USER017.dbf???????????? ONLINE
???????? 8 /oracle/CRM/test/TEST8.dbf?????????????? ONLINE
???????? 9 /oracle/CRM/test/POS9.dbf??????????????? ONLINE
???
???
例四 用switch tempfile all更新所有臨時數據文件位置和名字
SQL> select file#,name,status from v$tempfile;

???? FILE# NAME???????????????????????????????????? STATUS
---------- ---------------------------------------- -------
???????? 1 /oracle/CRM/temp01.dbf?????????????????? ONLINE
???????? 2 /oracle/CRM/newtemp.dbf????????????????? ONLINE
???
語句如下:???
startup force mount
run{
set newname for tempfile 1 to '/oracle/CRM/test/temp01.dbf';
set newname for tempfile 2 to '/oracle/CRM/test/temp02.dbf';
switch tempfile all;
alter database open;
}

執行過程如下:
RMAN> startup force mount

run{
set newname for tempfile 1 to '/oracle/CRM/test/temp01.dbf';
set newname for tempfile 2 to '/oracle/CRM/test/temp02.dbf';
switch tempfile all;
alter database open;
}
Oracle instance started
database mounted

Total System Global Area??? 1252663296 bytes

Fixed Size???????????????????? 2226072 bytes
Variable Size?????????????? 1006635112 bytes
Database Buffers???????????? 234881024 bytes
Redo Buffers?????????????????? 8921088 bytes

RMAN> 2> 3> 4> 5> 6>?
executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /oracle/CRM/test/temp01.dbf in control file
renamed tempfile 2 to /oracle/CRM/test/temp02.dbf in control file

database opened

RMAN> report schema;

Report of database schema for database with db_unique_name CRM

List of Permanent Datafiles
===========================
File Size(MB) Tablespace?????????? RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1??? 750????? SYSTEM?????????????? ***???? /oracle/CRM/test/SYSTEM1.dbf
2??? 540????? SYSAUX?????????????? ***???? /oracle/CRM/test/SYSAUX2.dbf
3??? 100????? UNDOTBS3???????????? ***???? /oracle/CRM/test/UNDOTBS33.dbf
4??? 1742???? USERS??????????????? ***???? /oracle/CRM/test/USERS4.dbf
5??? 500????? POS????????????????? ***???? /oracle/CRM/test/POS5.dbf
6??? 100????? ERP????????????????? ***???? /oracle/CRM/test/ERP6.dbf
7??? 5??????? USER01?????????????? ***???? /oracle/CRM/test/USER017.dbf
8??? 1??????? TEST???????????????? ***???? /oracle/CRM/test/TEST8.dbf
9??? 10?????? POS????????????????? ***???? /oracle/CRM/test/POS9.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace?????????? Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1??? 218????? TEMP???????????????? 32767?????? /oracle/CRM/test/temp01.dbf
2??? 3072???? MYNEWTEMP??????????? 40960?????? /oracle/CRM/test/temp02.dbf

例五 用switch datafile all更新表空間所有數據位置和名字
語句:
run{
sql 'alter tablespace pos offline immediate';
set newname for datafile '/oracle/CRM/test/POS5.dbf' to '/oracle/CRM/pos1.dbf';
set newname for datafile '/oracle/CRM/test/POS9.dbf' to '/oracle/CRM/pos2.dbf';
restore tablespace pos;
switch datafile all;
recover tablespace pos;
sql 'alter tablespace pos online';
}

執行過程如下:
RMAN> run{
2> sql 'alter tablespace pos offline immediate';
3> set newname for datafile '/oracle/CRM/test/POS5.dbf' to '/oracle/CRM/pos1.dbf';
4> set newname for datafile '/oracle/CRM/test/POS9.dbf' to '/oracle/CRM/pos2.dbf';
5> restore tablespace pos;
6> switch datafile all;
7> recover tablespace pos;
8> sql 'alter tablespace pos online';
9> }

sql statement: alter tablespace pos offline immediate

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2013-02-22 15:18:37
using channel ORA_DISK_1
using channel ORA_DISK_2

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 00005 to /oracle/CRM/pos1.dbf
channel ORA_DISK_1: restoring datafile 00009 to /oracle/CRM/pos2.dbf
channel ORA_DISK_1: reading from backup piece /backup/20130222_hho2k7jn_1_1
channel ORA_DISK_1: piece handle=/backup/20130222_hho2k7jn_1_1 tag=TAG20130222T145756
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 2013-02-22 15:19:03

datafile 5 switched to datafile copy
input datafile copy RECID=72 STAMP=808067944 file name=/oracle/CRM/pos1.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=73 STAMP=808067944 file name=/oracle/CRM/pos2.dbf

Starting recover at 2013-02-22 15:19:04
using channel ORA_DISK_1
using channel ORA_DISK_2

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 2013-02-22 15:19:05

sql statement: alter tablespace pos online

RMAN> report schema;

Report of database schema for database with db_unique_name CRM

List of Permanent Datafiles
===========================
File Size(MB) Tablespace?????????? RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1??? 750????? SYSTEM?????????????? ***???? /oracle/CRM/test/SYSTEM1.dbf
2??? 540????? SYSAUX?????????????? ***???? /oracle/CRM/test/SYSAUX2.dbf
3??? 100????? UNDOTBS3???????????? ***???? /oracle/CRM/test/UNDOTBS33.dbf
4??? 1742???? USERS??????????????? ***???? /oracle/CRM/test/USERS4.dbf
5??? 500????? POS????????????????? ***???? /oracle/CRM/pos1.dbf
6??? 100????? ERP????????????????? ***???? /oracle/CRM/test/ERP6.dbf
7??? 5??????? USER01?????????????? ***???? /oracle/CRM/test/USER017.dbf
8??? 1??????? TEST???????????????? ***???? /oracle/CRM/test/TEST8.dbf
9??? 10?????? POS????????????????? ***???? /oracle/CRM/pos2.dbf










本文轉自 zhangxuwl 51CTO博客,原文鏈接:http://blog.51cto.com/jiujian/1140329,如需轉載請自行聯系原作者

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/256574.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/256574.shtml
英文地址,請注明出處:http://en.pswp.cn/news/256574.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

服務核心 - 工具類

雖然類名稱為CWHService,我理解更多的是工具函數。 主要接口功能有: 1)SetClipboardString設置字符串到windows剪貼板 2)GetMachineID獲取機器標識,網卡地址MD5加密; 3)GetMachineIDEx獲取機器標…

現代制造工程課堂筆記07——應力應變分析(考點應力莫爾圓)

目錄 選擇判斷題,簡單計算在莫爾圓那里出 一、單向拉伸中的應力應變 手寫筆記 選擇判斷題,簡單計算在莫爾圓那里出 一、單向拉伸中的應力應變 、 手寫筆記

win10+tensorflow CPU 部署CTPN環境

剛弄明白CTPN部署的時候,CTPN作者剛更新了簡易代碼版本,看介紹是把代碼優化了不需要多的配置。。。感覺好憂傷! 源碼地址:https://github.com/eragonruan/text-detection-ctpn/tree/master 新版本地址:https://githu…

css如何實現背景透明,文字不透明?

之前做了個半透明彈層,但設置背景半透明時,子元素包含的字體及其它元素也都變成了半透明。對opacity這個屬性認識的不透徹,在這里做一些總結,方便以后使用。 背景透明,文字不透明的解決方法:為元素添加一個…

SQL Server 使用OPENROWSET訪問ORACLE遇到的各種坑總結

在SQL Server中使用OPENROWSET訪問ORACLE數據庫時,你可能會遇到各種坑,下面一一梳理一下你會遇到的一些坑。 1:數據庫沒有開啟"Ad Hoc Distributed Queries"選項,那么你就會遇到下面坑。 SELECT TOP 10 * FROM OPENROWS…

matlab——FFT傅里葉快速變換

目錄 一、自身的理解與補充 二、其他參考鏈接 一、轉載:https://blog.csdn.net/u013215903/article/details/48091359 FFT是Fast Fourier Transform(快速傅里葉變換)的簡稱,這種算法可以減少計算DFT(離散傅里葉變換,關于此更詳細的說明見后文)的時間,大大提高了運算效…

win10+tensorflow import cv2 bug解決

https://blog.csdn.net/sinat_21591675/article/details/82595812

設計理念 : popup login 在前后臺

popup 意思是一個遮罩層頂在整個網頁最前方,在前臺設計是這樣的,當用戶想在那個界面登入時,就可以有一個遮罩層出現。 在employer或admin(后臺)操作界面是同個理念,在所有的界面都是有control panel為根節點…

input和raw_input

12345678910python 2#!/usr/bin/env python#coding:utf-8nameraw_input("plese input you name") print namepython3#!/usr/bin/env python#coding:utf-8nameinput("plese input you name") print name本文轉自 小小三郎1 51CTO博客,原文鏈接…

MAATLAB GUI——回調函數的設置(Callbacks)

目錄 1.回調函數創建步驟 1)命令窗口中輸入guide,創建一個新的GUI界面窗口

是什么時候開始學習gulp了

轉自:http://www.ydcss.com/archives/18 簡介: gulp是前端開發過程中對代碼進行構建的工具,是自動化項目的構建利器;她不僅能對網站資源進行優化,而且在開發過程中很多重復的任務能夠使用正確的工具自動完成&#xff1…

011——數組(十一)array_merge array_merge_recursive array_change_key_case

<?php /***/ //array_merge() 將多個數組合并&#xff0c;生成新數組。當鍵名相同時&#xff0c;后者覆蓋前者 /*$array1array(weburl>"bbs.blog.com",webname>"博客"); $array2array(db_hot>"localhost",db_user>"root&qu…

matlab GUI——按下按鈕在指定的坐標下繪制函數圖像

目錄 1.組件布局 2.回調函數設置 3.編寫回調函數 1.組件布局 2.回調函數設置 右鍵單擊plot按鈕——查看回調——call backs

【轉】【UML】使用Visual Studio 2010 Team System中的架構師工具(設計與建模)

Lab 1: 應用程序建模 實驗目標 這個實驗的目的是展示如何在Visual Studio 2010旗艦版中進行應用程序建模。團隊中的架構師會通過建模確定應用程序是否滿足客戶的需求。 你可以創建不同級別的詳細模型&#xff0c;并將它們彼此結合、測試然后發布到你的開發計劃里。 在這個實驗中…

C語言:指針的幾種形式二

一、const指針 1、const int* p和int const* p:兩者意義是相同的。指向的內容是只讀數據&#xff0c;不可以q改變&#xff1b;但是指向的地址可以改變。2、int* const p&#xff1a;必須先對指針初始化&#xff0c;而且指向的地址是只讀的&#xff0c;不可以再被改變&#xff1…

深度學習基礎(一)起源

目錄 一、DP的前世 1.perceptron 2.NN 3.DP 二、DP的基礎知識 1.convolution 2.padding 3.pooling 4.Flatten 5.fully connected 6.dropout 一、DP的前世 深度學習發展至今經歷頗為曲折&#xff0c;上世紀起源&#xff0c;火熱起來也是20世紀初的時候&#xff0c;具體時…

ANSYS經典界面中梁單元實例全解析

轉載鏈接&#xff1a;http://www.jishulink.com/content/post/361389 文中紅色部分為自己添加&#xff01;&#xff01;&#xff01; 轉載的文章中提到的梁單元截面是常用的工字形&#xff0c;那么要是不規則的截面形狀的話需要自己進行截面形狀繪制&#xff0c;具體可以參考…

ant的安裝和使用

1.ant的安裝 1.1 添加環境變量&#xff1a;ANT_HOMED:\software\ant\apache-ant-1.10.1 在path中添加&#xff1a;%ANT_HOME%\bin 1.2 測試是否安裝成功 在cmd中輸入ant&#xff0c;如果出現如下提示表示安裝成功 2.定義簡單的build.xml 2.1 創建HelloWord.java package test; …

深度學習之tensorflow (一) XORerr1 -修改

博客背景是學習《深度學習之TensorFlow》這本書籍中的作業&#xff0c;修改第七章的作業&#xff0c;把XOR-異或的錯誤代碼修改為正確的。 主要修改有三個地方&#xff1a; 隱藏層一的運算從sigmoid修改為add運算&#xff1b;輸出層的運算修改為sigmoid&#xff08;原來是什么…