一、环境说明
源库 | 目标库 | |
IP | 192.168.37.200 | 192.168.37.202 |
系统版本 | RedHat 7.9 | RedHat 7.9 |
数据库版本 | 19.3.0.0.0 | 19.3.0.0.0 |
SID | beg | beg |
hostname | beg | rman |
数据量 | 1353M |
说明:源库已经创建数据库实例,并且存在用户kk和他创建的表空间和表,目标库只有数据库软件。
二、备份
2.1.日志清理(源端)
cd $ORACLE_BASE/diag/rdbms/beg/beg/trace
find ./ -name "*.trc" -ctime +15|xargs rm -f
find ./ -name "*.trm" -ctime +15|xargs rm -f
2.2.监听日志文件清理(源端)
cd /u01/app/oracle/diag/tnslsnr/beg/listener/alert
find ./ -name "*.xml" -ctime +15 |xargs rm -f
2.3.审计日志文件清理(源端)
cd /u01/app/oracle/admin/beg/adump
find ./ -name "*.aud" -ctime +15 |xargs rm -f
2.4.数据库目录备份(源端)
su – oracle
cd $ORACLE_HOME
cd ..
tar -cvzf db_home.tar.gz db/ #压缩至db同一目录
2.5.创建备份目录
su – oracle
mkdir –p /u01/app/store
--此目录是为了存储备份文件
2.6.创建rman用户
--创建表空间
CREATE TABLESPACE rman DATAFILE '/u01/app/oracle/oradata/BEG/rman.rdf' SIZE 125m AUTOEXTEND ON NEXT 50m MAXSIZE 1g;
--创建用户
create user rman identified by rman;
alter user rman default tablespace rman quota unlimited on rman;
--授权
grant recovery_catalog_owner to rman identified by rman;
2.7.备份原数据库
rman catalog rman/rman
--创建catalo
create catalog;
exit
2.8.添加监听
cd $ORACLE_HOME/dbs
vi tnsnames.ora
##添加以下内容
catalog =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = beg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = catalog)
)
)
2.9.注册数据库
rman target / catalog rman/rman@beg
register database;
2.10.开始备份
run {
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u01/app/store/%F';
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=0 database format '/u01/app/store/d_%T_%s.bak';
release channel d1;
release channel d2;
}
源数据库备份完毕,会在备份集目录中看到备份集:
----记录----
RMAN> run {
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u01/app/store/%F';
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=0 database format '/u01/app/store/d_%T_%s.bak';
release channel d1;
release channel d2;
}
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/store/ %F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/store/%F';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
allocated channel: d1
channel d1: SID=17 device type=DISK
allocated channel: d2
channel d2: SID=394 device type=DISK
Starting backup at 08-APR-24
channel d1: starting incremental level 0 datafile backup set
channel d1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/BEG/system01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/BEG/users01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/BEG/beg_data01.dbf
channel d1: starting piece 1 at 08-APR-24
channel d2: starting incremental level 0 datafile backup set
channel d2: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/BEG/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/BEG/undotbs01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/BEG/rman.rdf
channel d2: starting piece 1 at 08-APR-24
channel d2: finished piece 1 at 08-APR-24
piece handle=/u01/app/store/d_20240408_6.bak tag=TAG20240408T170731 comment=NONE
channel d2: backup set complete, elapsed time: 00:00:07
channel d1: finished piece 1 at 08-APR-24
piece handle=/u01/app/store/d_20240408_5.bak tag=TAG20240408T170731 comment=NONE
channel d1: backup set complete, elapsed time: 00:00:15
Finished backup at 08-APR-24
Starting Control File and SPFILE Autobackup at 08-APR-24
piece handle=/u01/app/store/c-2243024325-20240408-00 comment=NONE
Finished Control File and SPFILE Autobackup at 08-APR-24
released channel: d1
released channel: d2
三、在目标数据库还原数据库
3.1.传输备份集到目标端
su – oracle
cd /u01/app/store
scp d_20240408_5.bak d_20240408_6.bak c-2243024325-20240408-00 oracle@rman:/u01/app/store
3.2.传输配置到目标端
scp initbeg.ora orapwbeg oracle@rman:/u01/app/oracle/product/19.3.0/db/dbs
---在目标端编辑initbeg.ora配置文件
cd $ORACLE_HOME/dbs
vi initbeg.ora
##在文件末尾添加
_allow_resetlogs_corruption=true
3.3.创建adump目录
mkdir -p /u01/app/oracle/admin/beg/adump
3.4.以pfile启动目标数据库,启动rman
sas
startup pfile='/u01/app/oracle/product/19.3.0/db/dbs/initbeg.ora' nomount;
exit;
---查询源数据库的dnid
select dbid from v$database;
3.5.启动rman
rman
connect target / ;
set dbid=2243024325;
3.6.还原
-----还原控制文件
restore controlfile from '/u01/app/store/c-2243024325-20240408-00’;
-----还原初始配置文件
restore spfile from '/u01/app/store/c-2243024325-20240408-00’;
-----还原数据库
alter database mount;
restore database;
recover database;
Alter database open resetlogs;
四、验证
4.1.登录
#因为在源库中kk用户已经创建了,我们使用kk用户登录
sas
conn kk/oracle
4.2.查询
select count(*) from departments;
select count(*) from employees;
五、问题及解决
5.1.命令错误
--问题描述
[oracle@beg:/u01/app/oracle/oradata/BEG]$ rman target / catalog rman
………
RMAN-00552: syntax error in command line arguments
RMAN-01009: syntax error: found "rman": expecting one of: "double-quoted-string, identifier, single-quoted-string, "
RMAN-01007: at line 2 column 1 file: command line arguments
--解决办法
将命令修改成如下
rman target / catalog rman/rman@beg
--错误原因分析:
不熟悉rman命令导致的,需要对rman深入学习
5.2.非归档下无法进行backup操作
--问题描述
RMAN-03002: failure of backup command at 04/08/2024 16:26:56
RMAN-06149: cannot BACKUP DATABASE in NOARCHIVELOG mode
--问题分析:
数据库处于NOARCHIVELOG模式下,因此无法执行BACKUP DATABASE命令
--解决办法
切换到ARCHIVELOG模式
ALTER DATABASE ARCHIVELOG;
5.3.找不到相关目录
--问题描述:
在进行数据库备份的时候,提到了没有这个文件夹:
--解决思路:
起初怀疑是权限问提,在将该目录下以及他的目录之前的权限都赋予了oracle用户还是没有解决,最终排除下来是因为在store /%中间的位置加了一个空格,删除之后问题解。
run {
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u01/app/store/%F';
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level=0 database format '/u01/app/store/d_%T_%s.bak';
release channel d1;
release channel d2;
}
5.4.缺少相关目录
--问题描述
在通过pfile文件启动数据库到nomount状态时,报错没找相关目录或文件夹
--解决思路
找出缺失文件或目录,进行创建
--问题解决
报错内容为无法创建审计跟踪文件,检查从源端传输过来的配置文件:
发现这个文件没有创建,创建即可:
mkdir -p /u01/app/oracle/admin/beg/adump
之后启动正常,问题解决。