在Azure云中保护Oracle数据库
NetApp解决方案工程部的Allen Cao
本节介绍如何使用azacsnap工具以及快照备份、还原和快照分层到Azure Blob来保护Oracle数据库。
使用AzAcSnap工具使用Snapshot备份Oracle数据库
Azure应用程序一致的Snapshot工具(AzAcSnap)是一个命令行工具、可通过处理在创建存储快照之前将第三方数据库置于应用程序一致状态所需的所有流程编排来为其提供数据保护、之后、它会将数据库恢复为运行状态。
对于Oracle、您可以将数据库置于备份模式以创建快照、然后将数据库退出备份模式。
备份数据和日志卷
可以使用执行snapshot命令的简单shell脚本在数据库服务器主机上设置备份。然后、可以计划从crontab运行此脚本。
通常、备份频率取决于所需的RTO和RPO。频繁创建快照会占用更多存储空间。备份频率与空间占用之间存在一定的权衡。
数据卷通常比日志卷占用更多的存储空间。因此、您可以每几小时在数据卷上创建一次快照、而每15到30分钟在日志卷上创建一次更频繁的快照。
请参见以下备份脚本和计划示例。
对于数据卷快照:
# /bin/sh
cd /home/azacsnap/bin
. ~/.bash_profile
azacsnap -c backup --volume data --prefix acao-ora01-data --retention 36
azacsnap -c backup --volume other --prefix acao-ora01-log --retention 250
对于日志卷快照:
# /bin/sh
cd /home/azacsnap/bin
. ~/.bash_profile
azacsnap -c backup --volume other --prefix acao-ora01-log --retention 250
crontab计划:
15,30,45 * * * * /home/azacsnap/snap_log.sh 0 */2 * * * /home/azacsnap/snap_data.sh
设置备份时 azacsnap.json 配置文件中、将所有数据卷(包括二进制卷)添加到 dataVolume 以及所有日志卷 otherVolume 。快照的最大保留空间为250个副本。
|
验证快照
转至Azure门户> Azure NetApp文件/卷以检查是否已成功创建快照。
Oracle从本地备份还原和恢复
Snapshot备份的一个主要优势是、它与源数据库卷共存、并且主数据库卷几乎可以即时回滚。
在主服务器上还原和恢复Oracle
以下示例演示了如何从同一Oracle主机上的Azure信息板和CLI还原和恢复Oracle数据库。
-
在要还原的数据库中创建一个测试表。
[oracle@acao-ora01 ~]$ sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Mon Sep 12 19:02:35 2022 Version 19.8.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.8.0.0.0 SQL> create table testsnapshot( id integer, event varchar(100), dt timestamp); Table created. SQL> insert into testsnapshot values(1,'insert a data marker to validate snapshot restore',sysdate); 1 row created. SQL> commit; Commit complete. SQL> select * from testsnapshot; ID ---------- EVENT -------------------------------------------------------------------------------- DT --------------------------------------------------------------------------- 1 insert a data marker to validate snapshot restore 12-SEP-22 07.07.35.000000 PM
-
将此表放到快照备份之后。
[oracle@acao-ora01 ~]$ sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Tue Sep 13 14:20:22 2022 Version 19.8.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.8.0.0.0 SQL> drop table testsnapshot; Table dropped. SQL> select * from testsnapshot; select * from testsnapshot * ERROR at line 1: ORA-00942: table or view does not exist SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> exit Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.8.0.0.0
-
从Azure NetApp Files 信息板中、将日志卷还原到最后一个可用快照。选择*还原卷*。
-
确认还原卷并单击*还原*以完成卷还原到最新可用备份的过程。
-
对数据卷重复相同的步骤、并确保备份包含要恢复的表。
-
再次确认卷还原、然后单击"还原"。
-
如果您有多个控制文件副本、请重新同步这些控制文件、并将旧控制文件替换为可用的最新副本。
[oracle@acao-ora01 ~]$ mv /u02/oradata/ORATST/control01.ctl /u02/oradata/ORATST/control01.ctl.bk [oracle@acao-ora01 ~]$ cp /u03/orareco/ORATST/control02.ctl /u02/oradata/ORATST/control01.ctl
-
登录到Oracle服务器VM并使用sqlplus运行数据库恢复。
[oracle@acao-ora01 ~]$ sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Tue Sep 13 15:10:17 2022 Version 19.8.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount; ORACLE instance started. Total System Global Area 6442448984 bytes Fixed Size 8910936 bytes Variable Size 1090519040 bytes Database Buffers 5335154688 bytes Redo Buffers 7864320 bytes Database mounted. SQL> recover database using backup controlfile until cancel; ORA-00279: change 3188523 generated at 09/13/2022 10:00:09 needed for thread 1 ORA-00289: suggestion : /u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_43__22rnjq9q_.arc ORA-00280: change 3188523 for thread 1 is in sequence #43 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} ORA-00279: change 3188862 generated at 09/13/2022 10:01:20 needed for thread 1 ORA-00289: suggestion : /u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_44__29f2lgb5_.arc ORA-00280: change 3188862 for thread 1 is in sequence #44 ORA-00278: log file '/u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_43__22rnjq9q_.arc' no longer needed for this recovery Specify log: {<RET>=suggested | filename | AUTO | CANCEL} ORA-00279: change 3193117 generated at 09/13/2022 12:00:08 needed for thread 1 ORA-00289: suggestion : /u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_45__29h6qqyw_.arc ORA-00280: change 3193117 for thread 1 is in sequence #45 ORA-00278: log file '/u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_44__29f2lgb5_.arc' no longer needed for this recovery Specify log: {<RET>=suggested | filename | AUTO | CANCEL} ORA-00279: change 3193440 generated at 09/13/2022 12:01:20 needed for thread 1 ORA-00289: suggestion : /u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_46_%u_.arc ORA-00280: change 3193440 for thread 1 is in sequence #46 ORA-00278: log file '/u03/orareco/ORATST/archivelog/2022_09_13/o1_mf_1_45__29h6qqyw_.arc' no longer needed for this recovery Specify log: {<RET>=suggested | filename | AUTO | CANCEL} cancel Media recovery cancelled. SQL> alter database open resetlogs; Database altered. SQL> select * from testsnapshot; ID ---------- EVENT -------------------------------------------------------------------------------- DT --------------------------------------------------------------------------- 1 insert a data marker to validate snapshot restore 12-SEP-22 07.07.35.000000 PM SQL> select systimestamp from dual; SYSTIMESTAMP --------------------------------------------------------------------------- 13-SEP-22 03.28.52.646977 PM +00:00
此屏幕显示已删除的表已使用本地快照备份进行恢复。