导读
为减少主库的备份压力,在standby备库备份数据库,由于测试需要,现在在异机恢复一个数据库的测试环境,即利用standby数据库的备份恢复一个新的数据库。
1、查看standby 数据库备份脚本
#!/bin/sh
. ~/.bash_profile
DATE=`date +%Y-%m-%d-%H-%M-%S`
export oracle_SID=ORCLADG
rman target / log=/backup/log/rmanfull_ORCLADG_log_$DATE <<eof
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup as ***pressed backupset database format '/backup/data/dwprodadg/rmanfull_ORCLADG_%d_%T_%s_%p.bak';
backup archivelog all format '/backup/data/dwprodadg/archfull_ORCLADG_%T%U.bak';
backup spfile format '/backup/data/dwprodadg/spfile_dwprodadg_%d_%T_%s_%p.bak';
backup current controlfile format '/backup/data/dwprodadg/control_ORCLADG_%d_%T_%s_%p.bak';
crosscheck archivelog all;
delete force noprompt archivelog until time='sysdate-1';
crosscheck archivelog all;
delete noprompt expired archivelog all;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
eof
2、新服务器恢复数据库
新建一个服务器,安装好数据库软件,创建与standby数据库一样的数据目录和备份目录,归档目录,把备份的文件拷贝到新服务器。
注意:从standby备份来恢复一个数据库,需要使用主库备份的控制文件,否则恢复会失败。
主库备份控制文件
2.1、准备初始化参数文件
*.audit_file_dest='/u01/app/oracle/admin/ORCLADG/adump'
*.audit_trail='db'
*.***patible='11.2.0.4.0'
*.control_files='/data/oradata/ORCLADG/ORCLADG.ctl'
*.db_block_size=32768
*.db_create_file_dest='/data/oradata/ORCLADG'
*.db_domain=''
*.db_file_name_convert='+DATA/ORCLADG/datafile','/data/oradata/ORCLADG'
*.db_name='ORCL'
*.db_recovery_file_dest_size=644245094400
*.db_recovery_file_dest='/arch/ORCLADG/flashback'
*.db_unique_name='ORCLADG'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLADGGXDB)'
*.fal_client='ORCLADG'
*.fal_server='ORCL'
*.log_archive_config='DG_CONFIG=(ORCL,ORCLADG)'
*.log_archive_dest_1='LOCATION=/arch/ORCLADG/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCLADG'
*.log_archive_dest_2='service=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL'
*.log_archive_dest_state_2='defer'
*.log_file_name_convert='+DATA/ORCL/onlinelog','/data/oradata/ORCLADG'
*.open_cursors=300
*.pga_aggregate_target=300m
*.processes=800
*.remote_login_passwordfile='exclusive'
*.sessions=885
*.sga_max_size=1g
*.sga_target=1g
*.standby_file_management='AUTO'
*.undo_retention=7200
2.2、将数据库启动到nomount
export ORACLE_SID=ORCLADG
sqlplus / as sysdba
create spfile from pfile;
startup nomount
2.3、恢复控制文件
rman target /
backup current controlfile format '/home/oracle/pri_ctl.bak';
2.4、将数据库启动到mount
alter database mount;
2.5、注册备份文件:
rman target /
catalog start with '/backup/data';
2.6、修改备份的并行度
RMAN> show all;
RMAN configuration parameters for database with db_unique_name DWPRODADG are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ***PRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+HFDATA/dwprod/snapcf_DWPROD.f';
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 4;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are su***essfully stored
released channel: ORA_DISK_1
RMAN> show all;
RMAN configuration parameters for database with db_unique_name DWPRODADG are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ***PRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+HFDATA/dwprod/snapcf_DWPROD.f';
RMAN>
2.7、还原数据库
restore database;
2.8、恢复数据库
recover database;
2.9、以只读方式打开数据库
alter database open resetlogs;