实战:从Oracle standby数据库端备份数据库并在异机恢复一个新的数据库

导读

为减少主库的备份压力,在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 compressed 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'
*.compatible='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 COMPRESSION 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 successfully 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 COMPRESSION 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;
相关推荐
小白学大数据6 分钟前
JavaScript重定向对网络爬虫的影响及处理
开发语言·javascript·数据库·爬虫
time never ceases27 分钟前
使用docker方式进行Oracle数据库的物理迁移(helowin/oracle_11g)
数据库·docker·oracle
Frank牛蛙30 分钟前
1.每日SQL----2024/11/7
数据库·sql
Ciderw32 分钟前
块存储、文件存储和对象存储详细介绍
网络·数据库·nvme·对象存储·存储·块存储·文件存储
薛晓刚33 分钟前
数据库优化指南:如何将基本功能运用到极致?
数据库
stars_User36 分钟前
MySQL数据库面试题(下)
数据库·mysql
未来之窗软件服务1 小时前
sql速度优化多条合并为一条语句
数据库
山东布谷科技官方1 小时前
布谷直播源码部署服务器关于数据库配置的详细说明
运维·服务器·数据库·直播系统源码·直播源码·直播系统搭建·直播软件开发
易云码1 小时前
信息安全建设方案,网络安全等保测评方案,等保技术解决方案,等保总体实施方案(Word原件)
数据库·物联网·安全·web安全·低代码
newxtc2 小时前
【客观理性深入讨论国产中间件及数据库-科创基础软件】
数据库·中间件·国产数据库·国产中间件·科创