操作示例:
1、两个数据库,生产库tsid,catalog数据库cata数据库
2、查看生产库tsid是否是归档状态
C:\>sqlplus sys/password@tsid as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 5 17:27:24 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 96
Next log sequence to archive 98
Current log sequence 98
如果如上是enabled就是归档模式不用修改,如果上面列出的是disabled,修改为归档状态,需要先将数据库关闭,命令如下
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1248528 bytes
Variable Size 83886832 bytes
Database Buffers 188743680 bytes
Redo Buffers 7139328 bytes
Database mounted.
SQL> alter database archivelog;
3、建立两个库的关系
--连接cata库
C:\Users\Administrator>sqlplus sys/password@cata as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 5 13:32:50 2
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Produ
With the Partitioning, OLAP and Data Mining options
--创建用户rman用户
SQL> create user rman identified by rman default tablespace users
User created.
--赋予rman用户catalog权限
SQL> grant connect,resource,recovery_catalog_owner to rman;
Grant succeeded.
SQL>exit
--开启另外一个cmd窗口
--在rman中连接两个数据库
C:\Users\Administrator>rman target sys/password@tsid catalog rman/rman@cata
Recovery Manager: Release 10.2.0.1.0 - Production on Sat Jan 5 13:37:46 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=2066156567)
connected to recovery catalog database
--创建关联关系对象
RMAN> create catalog;
recovery catalog created
--注册到catalog库
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
--31天前的备份视为过期
RMAN> configure RETENTION POLICY TO recovery window of 31 days;
--保留最近的两份备份
RMAN> configure RETENTION POLICY TO redundancy 2;
以上是在cmd内执行的命令
以下是要运行的批处理,有两个文件,一个是包含sql语句的dbback.sql文件,一个是要运行的批处理rmanbackup.bat文件
Dbback.sql中的内容是
蓝色的文字是指备份文件存放的路径,可以修改为自己需要的路径
run{
allocate channel c1 type disk;
backup as compressed backupset full database format'G:/BACKUP/%U';
delete noprompt obsolete;
backup archivelog all;
release channel c1;
}
Rmanbackup.bat中的内容是
Password修改为数据库用户sys的密码,cmdfile后面的内容是死dbback.sql所在的路径名
Log是备份执行日志,路径是日志存放位置
rman target sys/password@tsid catalog rman/rman@cata cmdfile='K:\six\dbback.sql'
log='K:\dbbak.log' append
用windows执行计划或者oracle 定时任务让批处理在指定时间运行
以上备份策略完成
这种方法有两个缺陷,一是数据库密码曝露,可以通过操作系统登录解决,二是备份策略易被修改,可以创在数据库的脚本里。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25843472/viewspace-752213/ ,如需转载,请注明出处,否则将追究法律责任。