强烈建议把数据库设置成归档模式
一.数据库归档模式的设置方法
1.把database关闭后,修改init.ora,添加如下几行
log_archive_start=true
log_archive_dest= ---根据具体情况而定 eg. 'd:\oracle9i\oradata\'
log_archive_format=%s_%t.arc
说明:
>>log_archive_dest与log_archive_duplex_dest设置镜像;
>>log_archive_dest_n也是设置镜像,但与上面设置是互斥的;
2.用pfile参数文件把数据库设置成nomount状态
startup nomount pfile= ---就是init.ora所在的位置
然后再创建spfile
create spfile from pfile;
3.把数据库设置成mount状态
alter database mount;
alter database archivelog; ---设置数据库为归档模式
4.把数据库设置成open状态,即打开数据库
alter database open;
5.查看数据库是否为归档模式
archive log list;
二.设置RMAN环境
RMAN可以用目录数据库controlfile和单独的CATALOG执行数据库的备份和还原工作,强烈建议使用CATALOG执行数据库的备份和还原.
1.建数据表空间(tablespace)
create tablespace rmants
datafile 'd:\oracle9i\oradata\ivan\rmants01.dbf' size 10m autoextend on next 1m maxsize 100m
extent management local;
2.建用户(rman)
create user rman identified by rman
default tablespace rmants
temporary tablespace temp;
3.对用户rman授权
grant connect,resource,recovery_catalog_owner to rman;
4.用rman连接目录数据库
rman catalog rman/rman target ;
5.创建CATALOG
RMAN>create catalog ;
说明:此处没指定表空间,用户在默认表空间中创建(本文也就是rmants);
6.注册数据库
RMAN>register database;
7.同步CATALOG
RMAN>resync catalog;
至此,RMAN环境设置完毕!
三.RMAN常用命令
1.startup/shutdown,restore/recover,create catalog /drop catalog,backup/copy,run/show/sql/set/switch,
eg.
RMAN>run {
allocale channel c1 type disk;
sql ' alter tablespace tools offline immediate';
set newname for datafile 'd:\oracle9i\oradata\tool01.dbf' to 'c:\oracle\tools01.dbf';
restore database;
switch datafile all;
recover database;
sql ' alter tablespace tools online';
}
3.{create/replace/delete/execute/print} script script_name
eg.创建脚本backup_db_level_0
RMAN>create script backup_db_level_0{
allocate channel c1 type disk maxpiecesize 500M;
backup incremental level 0 database;
}
执行时
RMAN>run { execute script backup_db_level_0;}
说明:
RMAN脚本存储在RC_STORED_SCRIPT,RC_STORED_SCRIPT_LINE数据字典中
8.report
RMAN>report schema;
RMAN>report need backup incremental database;
RMAN>report unrecoverable;
RMAN>report obsolete;
9.delete
RMAN>delete obsolete;
10.crosscheck (交叉验证)
11.change ... available/unavailable
eg.
RMAN>change backup of database unavailable;
12.备份脚本执行
$ rman catalog rman/rman target cmdfile /home/oracle/scripts/rman.sql logfile /home/oracle/log/rman_$(date +%Y%m%d).log
rman.sql内容如下:
run {
allocate channel c1 type disk;
sql 'alter system archive log current';
backup format 'd:\oracle\archived\db_%u' (database include current controlfile);
backup format 'd:\oracle\archived\ar_%u' (archivelog like 'd:\oracle\archived\ARC%' delete all input );
release channel c1;
}
举例1: crosscheck/list/delete/change
RMAN>crosscheck backup -->查看备份集的状态:EXPIRED,AVAILABLE,UNAVAILABLE
RMAN>list expired backup of database -->列出过期的备份集
RMAN>delete expired backup of datbase -->删除过期的备份集
RMAN>change backup of database available -->把备份集状态改为available
举例2:configure配置参数
RMAN>configure controlfile autobackup on;
RMAN>configure retention policy to recovery window of 3 days;
RMAN>configure maxsetsize to 2G;
四.Making incremental backups
. Full backups contain all datafile blocks
. Differential incremental backups contain only modified blocks from the most recent backup at level n or lower
. Cumulative incremental backups contain only modified blocks from the previous backup at a level less than n-1 or lower