实战:从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;
相关推荐
LightOfNight1 小时前
Redis设计与实现第14章 -- 服务器 总结(命令执行器 serverCron函数 初始化)
服务器·数据库·redis·分布式·后端·缓存·中间件
代码中の快捷键1 小时前
MySQL数据库存储引擎的数据结构
数据结构·数据库·mysql
Adolf_19931 小时前
Django 路由层
数据库
好记忆不如烂笔头abc1 小时前
logminer挖掘日志归档查找问题
数据库·sql·mysql
java_heartLake9 小时前
PostgreSQL数据库参数调优实践
数据库·postgresql·调优
xnuscd10 小时前
Milvus概念
数据库·学习·mysql
代码欢乐豆11 小时前
软件工程第13章小测
服务器·前端·数据库·软件工程
小gpt&12 小时前
实现qt拖拽显示或者播放
数据库·qt·音视频
望获linux12 小时前
在 ARM 平台上如何实现Linux系统的1秒启动
linux·服务器·开发语言·数据库·操作系统·嵌入式操作系统·arm平台
漫天转悠12 小时前
MySQL 七种JOIN连接详解
数据库·mysql