ORACLE RMAN单机恢复

一、本地备份恢复(无NBU环境下)

本次备份恢复在单机环境进行
1、使用环境:将某一台数据库恢复到另一台数据库中。
2、环境准备:源数据库端备份数据,上传到目的数据库。目的主机安装数据库软件不创建库。
3、开始恢复

2 环境准备

目的主机安装数据库软件不创建库

推荐之前的oracle单机安装示例,此处不再说明。

2.1 源数据库备份

su - oracle
cat rman_backup.sh
#!/bin/bash
source ~/.bash_profile

BACKUP_DATE=`date +%Y%m%d`
BACKUP_TIME=`date +%H%M%S`
BACKUP_DATA_PATH=/oracle/backup/$BACKUP_DATE
BACKUP_LOG_PATH=/oracle/backup/log/$BACKUP_DATE

function rman_L0_backup()

{
   

rman target / nocatalog log=$BACKUP_LOG_PATH/L0_$BACKUP_TIME.log <<EOF

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 8 DAYS;
CONFIGURE ARCHIVELOG DELETION POLICY TO  BACKED UP 1 TIMES TO DEVICE TYPE DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "$BACKUP_DATA_PATH/%F";


crosscheck backup;
crosscheck backupset;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt archivelog until time 'SYSDATE-1';

run
{
   
allocate channel c1 device type disk maxpiecesize 20480M;
allocate channel c2 device type disk maxpiecesize 20480M;
allocate channel c3 device type disk maxpiecesize 20480M;

backup incremental level 0 database format '$BACKUP_DATA_PATH/L0_%d_%T_%s_%p.dbf';
sql 'alter system archive log current';
backup as compressed backupset archivelog all not backed up 1 times format '$BACKUP_DATA_PATH/L0_%d_%T_%s_%p.log';
backup current controlfile format '$BACKUP_DATA_PATH/L0_%d_%T_%s_%p.ctl';
backup spfile format '$BACKUP_DATA_PATH/L0_%d_%T_%s_%p.ora';
delete noprompt archivelog until time 'SYSDATE - 1/12';

release channel c1;
release channel c2;
release channel c3;
}

exit

EOF

}


function rman_L1_backup()

{
   

rman target / nocatalog log=$BACKUP_LOG_PATH/L1_$BACKUP_TIME.log <<EOF

CONFIGURE ARCHIVELOG DELETION POLICY TO  BACKED UP 1 TIMES TO DEVICE TYPE DISK;
run
{
   
allocate channel c1 device type disk maxpiecesize 20480M;
allocate channel c2 device type disk maxpiecesize 20480M;
allocate channel c3 device type disk maxpiecesize 20480M;

sql 'alter system archive log current';
backup as compressed backupset archivelog all not backed up 1 times format '$BACKUP_DATA_PATH/L1_%d_%T_%s_%p.log';
backup current controlfile format '$BACKUP_DATA_PATH/L1_%d_%T_%s_%p.ctl';
delete noprompt archivelog until time 'SYSDATE - 1/24';

release channel c1;
release channel c2;
release channel c3;
}

exit

EOF

}



if [ ! -d $BACKUP_LOG_PATH ]
then
    mkdir -p $BACKUP_LOG_PATH
fi

if [ -d $BACKUP_DATA_PATH ]
then
    rman_L1_backup
else
    mkdir -p $BACKUP_DATA_PATH
    rman_L0_backup
fi

#find /oracle/backup -mtime +4 |xargs rm -rf
find /oracle/backup -mtime +8 |xargs rm -rf
find /oracle/backup/log/* -mtime +9 |xargs rm -rf

2.2 将源数据库备份目录打包上传至目的主机

[oracle@ora19c backup]# zip 20230530.zip 20230530/*
  adding: 20230530/c-1601623831-20230530-05 (deflated 100%)
  adding: 20230530/c-1601623831-20230530-06 (deflated 100%)
  adding: 20230530/L0_CFCDB_20230530_26_1.dbf (deflated 84%)
  adding: 20230530/L0_CFCDB_20230530_27_1.dbf (deflated 68%)
  adding: 20230530/L0_CFCDB_20230530_28_1.dbf (deflated 63%)
  adding: 20230530/L0_CFCDB_20230530_29_1.dbf (deflated 85%)
  adding: 20230530/L0_CFCDB_20230530_30_1.dbf (deflated 85%)
  adding: 20230530/L0_CFCDB_20230530_31_1.dbf (deflated 63%)
  adding: 20230530/L0_CFCDB_20230530_32_1.dbf (deflated 95%)
  adding: 20230530/L0_CFCDB_20230530_33_1.dbf (deflated 81%)
  adding: 20230530/L0_CFCDB_20230530_35_1.log (deflated 24%)
  adding: 20230530/L0_CFCDB_20230530_36_1.log (deflated 80%)
  adding: 20230530/L0_CFCDB_20230530_37_1.log (deflated 81%)
  adding: 20230530/L0_CFCDB_20230530_38_1.ctl (deflated 100%)
  adding: 20230530/L0_CFCDB_20230530_39_1.ora (deflated 99%)

[oracle@ora19c backup]# scp 20230530.zip ora-recover01:$PWD
The authenticity of host 'ora-recover01 (192.168.111.202)' can't be established.
ECDSA key fingerprint is SHA256:g5wRAatHIbzOHNaO9hNP/pwTmDk6b1/3lm3Ucm2fxac.
ECDSA key fingerprint is MD5:b1:cc:4e:f3:00:f1:b3:df:9a:7a:74:70:be:8e:fc:a0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ora-recover01' (ECDSA) to the list of known hosts.
oracle@ora-recover01's password:
20230530.zip                                                                                                                                                                100%  703MB 145.8MB/s   00:04

3 开始恢复

3.1 目的主机解压 备份目录

[oracle@ora-recover01 backup]# unzip 20230530.zip
Archive:  20230530.zip
  inflating: 20230530/c-1601623831-20230530-05
  inflating: 20230530/c-1601623831-20230530-06
  inflating: 20230530/L0_CFCDB_20230530_26_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_27_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_28_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_29_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_30_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_31_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_32_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_33_1.dbf
  inflating: 20230530/L0_CFCDB_20230530_35_1.log
  inflating: 20230530/L0_CFCDB_20230530_36_1.log
  inflating: 20230530/L0_CFCDB_20230530_37_1.log
  inflating: 20230530/L0_CFCDB_20230530_38_1.ctl
  inflating: 20230530/L0_CFCDB_20230530_39_1.ora

3.2 配置环境变量

cat /home/oracle/.bash_profile
export PATH
export TMP=/tmp
export TMPDIR=
export ORACLE_SID=CFCDB
export ORACLE_BASE=/oracle/app/db
export ORACLE_HOME=/oracle/app/19.3.0/db_1
export ORACLE_UNQNAME=
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export EDITOR=vi
export LANG=en_US
export NLS_LANG=american_america.AL32UTF8
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
umask 022

3.3 编写pfile文件并创建相应目录

cat /oracle/app/19.3.0/db_1/dbs/initCFCDB.ora

*._optimizer_use_auto_indexes='OFF'
*.audit_file_dest='/oracle

你可能感兴趣的:(Oracle数据库知识集,oracle,数据库)