[20171221]利用rman實現2台機器文件拷貝.txt

来源:http://www.cnblogs.com/lfree/archive/2017/12/21/8079454.html
-Advertisement-
Play Games

[20171221]利用rman實現2台機器文件拷貝.txt--//昨天使用rman duplicate建立dg,我看到執行如下代碼:RMAN> duplicate target database for standby from active database nofilenamecheck;.. ...


[20171221]利用rman實現2台機器文件拷貝.txt

--//昨天使用rman duplicate建立dg,我看到執行如下代碼:

RMAN> duplicate target database for standby from active database nofilenamecheck;
...
contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/orapwbook' auxiliary format
 '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/orapwbookdg'   ;
}

--//是否通過這樣的方式可以實現2台伺服器之間文件拷貝呢?

1.環境:
SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.先測試oracle的口令文件是否可以傳輸:

$ rlwrap rman target sys/oracle@book auxiliary sys/oracle@bookdg
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Dec 21 10:35:47 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: BOOK (DBID=1337401710)
connected to auxiliary database: BOOK (DBID=1337401710)

RMAN> backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/orapwbook' auxiliary format '/tmp/orapwbookdg'   ;
Starting backup at 2017-12-21 10:36:16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=106 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=119 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=132 device type=DISK
Finished backup at 2017-12-21 10:36:18

--//在備庫檢查發現
$ ls -l /tmp/orapwbookdg
-rw-r-----  1 oracle oinstall 1536 2017-12-21 10:36:17 /tmp/orapwbookdg

3.測試其它用戶文件:

--//檢查主庫存在如下文件在/home/oracle,繼續測試看看:
$ ls -l aaa.txt
-rw-r--r-- 1 oracle oinstall 54 2017-11-16 11:42:50 aaa.txt

RMAN> backup as copy reuse targetfile '/home/oracle/aaa.txt' auxiliary format '/tmp/aaa.txt.bookdg'   ;
Starting backup at 2017-12-21 10:40:14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=106 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=119 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=132 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/21/2017 10:40:17
ORA-19505: failed to identify file "/home/oracle/aaa.txt"
ORA-27046: file size is not a multiple of logical block size
Additional information: 1

--//可以發現不行,文件大小必須是logical block size的整數倍.換一句話文件大小必須是512的倍數.
--//一些發行版本有fallocate可以給文件分配空間.
$ fallocate  -l 512 aaa.txt
--//我的測試機器沒有,我使用dd,需要加入512-54 = 458位元組

$ dd if=/dev/zero of=aaa.txt seek=54 count=458  bs=1 conv=notrunc
458+0 records in
458+0 records out
458 bytes (458 B) copied, 0.00208456 seconds, 220 kB/s

--//再次提醒加入輸入輸出不要寫反.寫入onv=notrunc不管怎樣都不會錯,這樣避免被切斷,我個人每次使用dd都心存敬畏..因為1次差錯....
--//註意這樣寫效率不高bs=1.(意味每次寫1個位元組,寫458次),因為前面的seek參數對應54*1,
--//如果你反過來寫count=1  bs=458 ,相當於在54*458偏移開始寫入.利用這個特性實際上這樣執行:

$ ls -l aaa.txt
-rw-r--r-- 1 oracle oinstall 54 2017-12-21 10:55:17 aaa.txt

$ dd if=/dev/zero of=aaa.txt seek=511 count=1  bs=1 conv=notrunc
1+0 records in
1+0 records out
1 byte (1 B) copied, 5.2118e-05 seconds, 19.2 kB/s

$ ls -l aaa.txt
-rw-r--r-- 1 oracle oinstall 512 2017-12-21 10:56:52 aaa.txt

RMAN> backup as copy reuse targetfile '/home/oracle/aaa.txt' auxiliary format '/tmp/aaa.txt.bookdg'   ;
Starting backup at 2017-12-21 10:58:05
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
Finished backup at 2017-12-21 10:58:06

--//OK,現在拷貝過去了.

--//主庫:
$ md5sum /home/oracle/aaa.txt
94a6edaabd20f62185e62037f2dbcb21  /home/oracle/aaa.txt

--//備庫:
$ md5sum /tmp/aaa.txt.bookdg
94a6edaabd20f62185e62037f2dbcb21  /tmp/aaa.txt.bookdg

--//md5一樣,說明沒有問題.另外我的測試不使用reuse參數也會覆蓋對面的文件.這點要特別註意!!

RMAN> backup as copy  targetfile '/home/oracle/aaa.txt' auxiliary format '/tmp/aaa.txt.bookdg'   ;

Starting backup at 2017-12-21 11:05:48
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
Finished backup at 2017-12-21 11:05:49

4.延伸測試:
--//是否這樣可以實現備份:
RMAN> backup as backupset   datafile 6 auxiliary format '/data/testtest/datafile6_%U'  ;
Starting backup at 2017-12-21 11:21:00
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 12/21/2017 11:21:00
RMAN-06955: Network copies are only supported for image copies.

--//^_^,oracle不支持,報RMAN-06955: Network copies are only supported for image copies.
--//也就是做image copy應該沒有問題.

RMAN> backup as copy  datafile 6 auxiliary  format '/data/backuptest/datafile6_%U'   ;
Starting backup at 2017-12-21 11:28:22
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/data/backuptest/datafile6_data_D-BOOK_I-1337401710_TS-TEA_FNO-6_fpsmm16m tag=TAG20171221T112822
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2017-12-21 11:28:23

RMAN> backup as copy  datafile 6 auxiliary  format '/data/backuptest/%b'   ;
Starting backup at 2017-12-21 11:29:01
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/data/backuptest/tea01.dbf tag=TAG20171221T112901
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2017-12-21 11:29:02
--//OK沒有問題.

$ ls -l /data/backuptest
total 12328
-rw-r-----  1 oracle oinstall 6299648 2017-12-21 11:28:22 datafile6_data_D-BOOK_I-1337401710_TS-TEA_FNO-6_fpsmm16m
-rw-r-----  1 oracle oinstall 6299648 2017-12-21 11:29:01 tea01.dbf

$ dbv file=/data/backuptest/tea01.dbf
DBVERIFY: Release 11.2.0.4.0 - Production on Thu Dec 21 11:31:29 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
DBVERIFY - Verification starting : FILE = /data/backuptest/tea01.dbf
DBVERIFY - Verification complete
Total Pages Examined         : 768
Total Pages Processed (Data) : 594
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 128
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 46
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 392434057 (3.392434057)
--//說明沒有問題.註意這樣備份在控制文件沒有記錄.

--//主庫:
RMAN> list copy of datafile 6;
specification does not match any datafile copy in the repository

--//有點可惜的是11g不支持copy section size,也就是分段拷貝.12c支持,這樣可以加快copy的速度.
--//參考鏈接:http://blog.itpub.net/267265/viewspace-1310778/

總結:
1.這樣方式拷貝文件大小存在限制,必須是512的倍數.
2.提供另外一種手工方式建立備庫的方式.
3.另外註意這樣拷貝方式在控制文件沒有記錄.
4.註意文件覆蓋問題.似乎數據文件copy不會覆蓋,除非指定resue參數,參考後面測試:
5.補充測試:

RMAN> backup as copy  database auxiliary  format '/data/backuptest/%b'   ;
Starting backup at 2017-12-21 11:39:12
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf
channel ORA_DISK_2: starting datafile copy
input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf
channel ORA_DISK_3: starting datafile copy
input datafile file number=00001 name=/mnt/ramdisk/book/system01.dbf
output file name=/data/backuptest/system01.dbf tag=TAG20171221T113912
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_3: starting datafile copy
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
output file name=/data/backuptest/sysaux01.dbf tag=TAG20171221T113912
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:58
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
output file name=/data/backuptest/undotbs01.dbf tag=TAG20171221T113912
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:58
channel ORA_DISK_2: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
--//視乎文件存在不會覆蓋..
RMAN-03009: failure of backup command on ORA_DISK_2 channel at 12/21/2017 11:40:12
ORA-17628: Oracle error 19505 returned by remote Oracle server
continuing other job steps, job failed will not be re-run
output file name=/data/backuptest/users01.dbf tag=TAG20171221T113912
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:17
output file name=/data/backuptest/example01.dbf tag=TAG20171221T113912
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:20
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_2 channel at 12/21/2017 11:40:12
ORA-17628: Oracle error 19505 returned by remote Oracle server

--//刪除前面的備份在重新執行:
RMAN> backup as copy  database auxiliary  format '/data/backuptest/%b'   ;

Starting backup at 2017-12-21 11:43:09
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf
channel ORA_DISK_2: starting datafile copy
input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf
channel ORA_DISK_3: starting datafile copy
input datafile file number=00001 name=/mnt/ramdisk/book/system01.dbf
output file name=/data/backuptest/sysaux01.dbf tag=TAG20171221T114309
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
output file name=/data/backuptest/undotbs01.dbf tag=TAG20171221T114309
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:01:06
channel ORA_DISK_2: starting datafile copy
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
output file name=/data/backuptest/system01.dbf tag=TAG20171221T114309
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:01:06
channel ORA_DISK_3: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/data/backuptest/tea01.dbf tag=TAG20171221T114309
channel ORA_DISK_3: datafile copy complete, elapsed time: 00:00:03
output file name=/data/backuptest/example01.dbf tag=TAG20171221T114309
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
output file name=/data/backuptest/users01.dbf tag=TAG20171221T114309
channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:15
Finished backup at 2017-12-21 11:44:30
--//ok!!

RMAN> backup as copy  datafile 6 auxiliary  format '/data/backuptest/%b'   ;
Starting backup at 2017-12-21 11:45:32
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/21/2017 11:45:33
ORA-17628: Oracle error 19505 returned by remote Oracle server

--//視乎不能覆蓋.加入resue看看.

RMAN> backup reuse as copy  datafile 6 auxiliary  format '/data/backuptest/%b'   ;

Starting backup at 2017-12-21 11:46:19
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
output file name=/data/backuptest/tea01.dbf tag=TAG20171221T114619
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2017-12-21 11:46:20



您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 最近因為要學習Python,於是把放在家裡接了一年灰的樹莓派又給搜出來了,剛買那會也搗鼓了好一陣子, 基本操作都學會了,但現在又忘光了,只能又從頭開始搞了,首先第一個要解決的是怎麼把文件從電腦傳輸到樹莓派 ,記得以前是在Windows上傳的,直接在網上下載了一個軟體,filezilla,打開輸入板卡 ...
  • 通過啟用屏幕共用來開啟遠程桌面登錄,開啟後需要關閉encryption,否則會出現無法連接的情況。關閉encryption可以使用系統配置工具dconf來完成。所以先安裝dconf-editor。 更新源並安裝系統配置工具(不更新源無法進行安裝) 1、查看系統版本 2、添加更新源,更新源內容可以從網 ...
  • 一、環境 VMware12 Pro CentOS-6.7-i386-bin-DVD1 jdk-8u151-linux-i586 二、詳細安裝步驟 前提:需要卸載自己Linux上的jdk rpm -qa | grep jdk 會顯示你所有包含jdk這個字元串的安裝包 rpm -e --nodeps 對 ...
  • 目錄 一、概述 二、MySQL安裝 三、安裝成功驗證 四、NavicatforMySQL下載及使用 一、概述 MySQL版本:5.7.17 下載地址:http://rj.baidu.com/soft/detail/12585.html?ald 客戶端工具:NavicatforMySQL 綠色版下載地 ...
  • 項目需要定時備份資料庫,以下是自己的操作筆記 1.檢查磁碟空間 這是我當前linux伺服器的情況,至於為什麼是這樣子,我也不清楚(我是半路接過來的,無奈) 根據上面的信息,我就把備份文件放在/dev目錄下麵 2.創建備份目錄 3.創建備份shell命令 輸入如下內容 對備份進行壓縮 註意: 把 us ...
  • 在增量部署系統的時候, 經常需要提供增量修改的腳本, 如果是修改存儲過程或者自定義函數, 那還是很好改的, 不用擔心表功能收到影響. 如果是改欄位呢? 首先不知道欄位是不是已經在系統裡面, 沒有的話, 需要新增上去, 有的話, 需不需要修改? 其次, 腳本如果報錯, 是否會重覆執行一下腳本? 會不會 ...
  • 目的: 增加約束 創建索引 使用CREATE TABLE語句創建索引 創建函數索引 刪除列和將列置為UNUSED 平臺FLASHBACK閃回操作 創建臨時表 創建和使用外部表 ALTER TABLE語句 -增加列 -修改已存在的列 -定義列的預設值 -刪除列 語法 ALTER TABLE table ...
  • MySQL5.7單實例二進位包安裝方法 一、環境 OS: CentOS release 6.9 (Final)MySQL: mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 說明:類似的操作系統也可以的。為了方便起見,涉及到的操作,均可以直接粘貼複製,比較直觀快捷 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...