温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ORACLE_数据库全备份+归档异地恢复

发布时间:2020-08-04 19:39:36 来源:ITPUB博客 阅读:250 作者:adamjunior 栏目:关系型数据库

全备份:

#!/bin/bash 

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=ORCL

export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH

backtime=`date +"%y%m%d%H%M%S"`

$ORACLE_HOME/bin/rman target /   log=/home/oracle/full_backup_$backtime.log <<EOF 

run{

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

allocate channel c4 device type disk;

sql 'alter system archive log current'; 

backup as compressed backupset full database format '/u01/app/oracle/back/full_%d_%T_%U'; 

sql 'alter system archive log current';

backup archivelog all format '/u01/app/oracle/back/arch_%d_%T_%s_%p.bak' delete input ;

backup current controlfile format '/u01/app/oracle/back/ctl_%d_%T_%s_%p.bak';

release channel c1;

release channel c2;

release channel c3;

release channel c4;

}

EOF

备份归档日志

RMAN > run {

backup archivelog all format '/u01/app/oracle/back/arch_%d_%T_%s_%p.bak' delete input ;

backup current controlfile format '/u01/app/oracle/back/ctl_%d_%T_%s_%p.bak';

}

备份参数文件

SQL> create pfile from spfile;

恢复至其他环境

1.修改参数文件路径

vi $ORACLE_HOME/dbs/initORCL.ora

2.启动数据库至nomount

SQL> startup pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initORCL.ora';

3.恢复控制文件

$ cd /u01/app/oracle/backup

RMAN> restore controlfile from '/u01/app/oracle/backup/ctl_ORCL_20200311_19_1.bak';

RMAN> alter database mount;

3.恢复数据库

RMAN> run {

catalog start with '/u01/app/oracle/backup';

set newname for database to '/u01/app/oracle/oradata/DEMO/%U';

restore database;

switch datafile all;

switch tempfile all;

recover database;

}

Do you really want to catalog the above files (enter YES or NO)? yes

5. 修改日志文件

SQL> alter database rename file '/u01/app/oracle/oradata/ORCL/redo01.log' to '/u01/app/oracle/oradata/DEMO/redo01.log';

SQL> alter database rename file '/u01/app/oracle/oradata/ORCL/redo02.log' to '/u01/app/oracle/oradata/DEMO/redo02.log';

SQL> alter database rename file '/u01/app/oracle/oradata/ORCL/redo03.log' to '/u01/app/oracle/oradata/DEMO/redo03.log';

SQL>  ALTER DATABASE CLEAR LOGFILE GROUP 1;

SQL>  ALTER DATABASE CLEAR LOGFILE GROUP 2;

SQL>  ALTER DATABASE CLEAR LOGFILE GROUP 3;

6. 打开数据库

SQL> alter database open resetlogs;

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI