技术分享
RMAN压缩备份本地数据库与进行异地恢复操作
2021-06-01
RMAN压缩备份本地数据库,进行异地恢复操作:
原来数据库IP: A:172.21.1.30
要恢复的库IP: B:172.21.1.40
服务器A:172.21.1.30上的操作如下:
1.删除/bk下的所有备份文件,删除/arc下的归档文件
[oracle@dg ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 2 10:59:27 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: DG01 (DBID=370021178)
RMAN>delete noprompt expired backup;
RMAN>delete noprompt expired copy;
2.执行脚本 rmanback.sh,对数据库进行压缩备份:
脚本内容如下:
rman target / log=/bk/rmanbackup.log <<EOF
backup as compressed backupset filesperset 3 database format '/bk/%u';
backup archivelog all delete input format '/bk/arc_%u.bk';
delete noprompt obsolete;
backup current controlfile format '/bk/%u.ctl';
EOF
[oracle@dg ~]$sh /bk/rmanback.sh
[oracle@dg bk]$ ls
08mivn8k 09mivnci 0amivnd1 0bmivndq 0cmivne9 0emivneh.ctl arc_0dmivnee.bk rmanback.sh rmanbackup.log
[oracle@dg bk]$ tar cvfz bk30.tar.gz ./* --exclude=*.sh --exclude=*.log
[oracle@dg bk]$ scp -r bk30.tar.gz 172.21.1.40:/disk/
3.一致性停数据库:
[oracle@dg ~]$ sqlplus / as sysdba
SYS_S:142_P:13539_dg01>shutdown immediate;
服务器B:172.21.1.40 的操作步骤:
1.解压备份文件:
[oracle@vcdog disk]$ tar xvfz bk30.tar.gz ./
[oracle@vcdog disk]$ ls
08mivn8k 09mivnci 0amivnd1 0bmivndq 0cmivne9 0emivneh.ctl arc_0dmivnee.bk
2.恢复controlfile及spfile:
[oracle@vcdog disk]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Aug 2 11:22:07 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN>startup nomount;
RMAN>restore controlfile from '/disk/0emivneh.ctl';
RMAN>restore spfile from '/disk/0cmivne9';
[oracle@vcdog disk]$ cp $ORACLE_HOME/dbs/cntrlorcl.dbf $ORACLE_BASE/oradata/dg01/control01.ctl
[oracle@vcdog disk]$ cp $ORACLE_HOME/dbs/cntrlorcl.dbf $ORACLE_BASE/oradata/dg01/control02.ctl
[oracle@vcdog disk]$ cp $ORACLE_HOME/dbs/cntrlorcl.dbf $ORACLE_BASE/oradata/dg01/control03.ctl
[oracle@vcdog disk]$strings $ORACLE_HOME/dbs/spfiledg01.ora > $ORACLE_HOME/dbs/initdg01.ora
[oracle@vcdog disk]$ vim /data/oracle/product/10.2.0.1.0/db_01/dbs/initdg01.ora
*.audit_file_dest='/data/oracle/admin/dg01/adump'
*.background_dump_dest='/data/oracle/admin/dg01/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/data/oracle/oradata/dg01/control01.ctl','/data/oracle/oradata/dg01/control02.ctl','/data/oracle/oradata/dg01/control03.ctl'#Restore Controlfile
*.core_dump_dest='/data/oracle/admin/dg01/cdump'
*.db_block_size=8192
*.db_cache_size=62914560
*.db_file_multiblock_read_count=16
*.db_name='dg01'
*.job_queue_processes=2
*.large_pool_size=20971520
*.pga_aggregate_target=16777216
*.processes=150
*.sga_max_size=314572800
*.sga_target=293601280
*.shared_pool_size=96468992
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/data/oracle/admin/dg01/udump'
保存退出。
3.启动数据库到mount状态:
[oracle@vcdog dbs]$ sqlplus / as sysdba
SYS_S:159_P:5659_dg01> alter database mount;
SYS_S:159_P:5659_dg01>select 'set newname for datafile '||file#|| ' to '''||replace(name,'u01','data')||''';' from v$datafile;
set newname for datafile 1 to '/data/oracle/oradata/dg01/system01.dbf';
set newname for datafile 2 to '/data/oracle/oradata/dg01/undotbs01.dbf';
set newname for datafile 3 to '/data/oracle/oradata/dg01/sysaux01.dbf';
set newname for datafile 4 to '/data/oracle/oradata/dg01/users01.dbf';
set newname for datafile 5 to '/data/oracle/oradata/dg01/example01.dbf';
set newname for datafile 6 to '/data/oracle/oradata/dg01/vc.dbf';
set newname for datafile 7 to '/data/oracle/oradata/dg01/mytest01.dbf';
set newname for datafile 8 to '/data/oracle/oradata/dg01/mytest02.dbf';
set newname for datafile 9 to '/data/oracle/oradata/dg01/mytbs01.dbf';
set newname for datafile 10 to '/data/oracle/oradata/dg01/ind_tbs01.dbf';
set newname for datafile 11 to '/data/oracle/oradata/dg01/wd01.dbf';
4.RMAN下执行脚本:
RMAN> catalog start with '/disk/';
RMAN>run{
set newname for datafile 1 to '/data/oracle/oradata/dg01/system01.dbf';
set newname for datafile 2 to '/data/oracle/oradata/dg01/undotbs01.dbf';
set newname for datafile 3 to '/data/oracle/oradata/dg01/sysaux01.dbf';
set newname for datafile 4 to '/data/oracle/oradata/dg01/users01.dbf';
set newname for datafile 5 to '/data/oracle/oradata/dg01/example01.dbf';
set newname for datafile 6 to '/data/oracle/oradata/dg01/vc.dbf';
set newname for datafile 7 to '/data/oracle/oradata/dg01/mytest01.dbf';
set newname for datafile 8 to '/data/oracle/oradata/dg01/mytest02.dbf';
set newname for datafile 9 to '/data/oracle/oradata/dg01/mytbs01.dbf';
set newname for datafile 10 to '/data/oracle/oradata/dg01/ind_tbs01.dbf';
set newname for datafile 11 to '/data/oracle/oradata/dg01/wd01.dbf';
restore database;
switch datafile all;
recover database;
}
5.rename logfile日志文件:
[oracle@vcdog dbs]$scp -r 172.21.1.30:/u01/oracle/oradata/dg01/redo01.log /data/oracle/oradata/dg01/redo01.log
[oracle@vcdog dbs]$scp -r 172.21.1.30:/u01/oracle/oradata/dg01/redo03.log /data/oracle/oradata/dg01/redo03.log
SYS_S:159_P:5659_dg01>alter database rename file '/u01/oracle/oradata/dg01/redo01.log' to '/data/oracle/oradata/dg01/redo01.log';
SYS_S:159_P:5659_dg01>alter database rename file '/u01/oracle/oradata/dg01/redo03.log' to '/data/oracle/oradata/dg01/redo03.log';
此时,由于原来备份时,redo02.log文件是current状态,不能直接归档。在服务器A:172.21.1.30上执行如下命令:
SYS_S:159_P:5659_dg01>alter system switch logfile;
[oracle@vcdog dbs]$scp -r 172.21.1.30:/u01/oracle/oradata/dg01/redo02.log /data/oracle/oradata/dg01/redo02.log
SYS_S:159_P:5659_dg01>alter database rename file '/u01/oracle/oradata/dg01/redo02.log' to '/data/oracle/oradata/dg01/redo02.log';
6.打开数据库到open状态:
SYS_S:159_P:5659_dg01> alter database open resetlogs;
此时,数据库的异地恢复完成。
- 标签:
-
网络安全