脱机备份:
run{shutdown immediate;
startup mount;
allocate channel ch0 device type disk
format 'd:\backup\full_%U';
backup database
tag cold_full_backup;
sql 'alter database open';
release channel ch0;
}
联机全备份:
run{allocate channel ch0 device type disk
format 'd:\backup\full_%d_%U';
backup database
include current controlfile
tag full_bak
skip readonly;
backup archivelog all delete input;
release channel ch0;
}
list backup;
使用catalog db, 一般不和生产库放在一个server上。
create user rman identified by rman;
create tablespace rman datafile 'C:\oracle\product\10.2.0\oradata\ora10g\rman.dbf' size 100M;
grant connect,resource,recovery_catalog_owner to rman;
alter user rman default tablespace rman;
conn rman/rman
rman catalog rman/rman target sys/oracle;
create catalog;
register database;
使用sqlplus rman/rman 可以查看catalog使用的表
备份archive log:
run{allocate channel ch0 device type disk;
backup archivelog all delete input;
release channel ch0;
}
备份表空间:
表空间脱机备份:
RMAN> run{
allocate channel ch0 device type disk
format 'd:\backup\users01.bak';
sql 'alter tablespace users offline normal';
backup tablespace users[,system](备份多个表空间)
tag users01_bak;
sql 'alter tablespace users online';
release channel ch0;
}
表空间联机备份:
RMAN> run{
allocate channel ch0 device type disk
format 'd:\backup\users02.bak';
backup tablespace users[,system](备份多个表空间)
tag users03_bak;
release channel ch0;
}
增量备份:
SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE 'C:\oracle\product\10.2.0\oradata\ora10g\rman_change_track.f' REUSE;
设置后,增量备份会变快。
RMAN> run{
allocate channel ch0 device type disk
format 'd:\backup\incre%U';
backup incremental level 0 database;
backup archivelog all;
release channel ch0;
}
RMAN> run{
allocate channel ch0 device type disk
format 'd:\backup\incre%U';
backup incremental level 1 database;
backup archivelog all;
release channel ch0;
}
使用RMAN恢复:
如果数据库不是在OPEN状态:
rman target sys/oracle nocatalog
RMAN> run{
2> allocate channel ch1 device type disk;
3> restore tablespace users;
4> recover tablespace users;
5> release channel ch1;
6> }
如果数据库在OPEN状态:
rman catalog rman/rman target sys/oracle
RMAN> run{
allocate channel ch0 device type disk;
sql 'alter tablespace users offline immediate';
restore tablespace users;
recover tablespace users;
sql 'alter tablespace users online';
release channel ch0;
}
RMAN> run{
allocate channel ch1 device type disk;
restore database;
recover database;
release channel ch1;
}
如果online redo log和数据文件都丢了:
1. unix/linux 要设置环境变量
NLS_LANG = american_ameria.us7ascii
NLS_FORMAT='Mon DD YYYY HH:II:SS';
2. startup
3. rman nocatalog
4. Windows 可以不设置环境变量,使用函数to_date
RMAN> run{
allocate channel ch0 device type disk;
set until time "to_date('2009-11-01 16:17:00', 'YYYY-MM-DD HH24:MI:SS')";
restore database;
recover database;
release channel ch0;
}
5. sqlplus> alter database open resetlogs
或者 rman> sql 'alter database open resetlogs';
如果控制文件也丢失了:
1. shutdown abort
2. 删除所有文件
3. startup 报错,找不到controlfile
4. rman target sys/oracle
5. SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'D:\BACKUP\%F';
6. restore controlfile from autobackup;
如果报错并提示:由于未设置 DBID 而未尝试在恢复区域之外搜索自动备份
那么执行:SET DBID=4020644191(从'D:\BACKUP\%F'找到已经备份的控制文件,例如:C-4020644191-20091101-0F,取第一串数字作为DBID)
重新执行 restore controlfile from autobackup;
7. sql 'alter database mount';
8. run{
allocate channel ch0 device type disk;
restore database;
recover database;
release channel ch0;
}
9. alter database open resetlogs;
resetlogs后最好做脱机全备份
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22021749/viewspace-617857/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22021749/viewspace-617857/