[20171221]利用rman實現2臺機器檔案拷貝

lfree發表於2017-12-21

[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

--//如果害怕這樣操作,手工建立檔案大小512倍數.千萬不要拿重要檔案做這樣測試.

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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2149020/,如需轉載,請註明出處,否則將追究法律責任。

相關文章