DBA之RMAN备份
13:00
backup database
backup db :3h
3h: 产生了10 archive log file
16:00 finish
restore database;
13:00 : datafile不一致(因为没有备份archive log,controlfile)
job调用方式
vi /tmp/1.rcv
CONFIGURE CONTROLFILE AUTOBACKUP ON;
方式一 : rman target / @'/tmp/1.rcv'
方式二 :rman target / cmdfile=/tmp/1.rcv log=/tmp/rman.log
方式三 : sh script
内容如下
#!/bin/sh
rman target log=/tmp/rman.log append <<EOF
CONFIGURE CONTROLFILE AUTOBACKUP ON;
EOF;
---------------------------------------------------------------------------------------
备份策略
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
一般的我们这样设置
configure retention policy to recovery window of 30 days;
最简单的可恢复的备份
run{
backup database including archivelog format '/backup/db_%d_%s_%p_%T.bkp';
backup current controlfile format '/backup/cf_%d_%s_%p_%T.bkp';
}
标准备份
online
run{
allocate channel c1 type disk maxpiecesize=20G;
allocate channel c2 type disk maxpiecesize=20G;
sql 'alter system archive log current';
backup database format '/backup/db_%d_%s_%p_%T.bkp' tag 'db_backup_full';
backup archivelog all delete input format '/backup/log_%d_%s_%p_%T.bkp' tag 'log_backup_full';
backup current controlfile format '/backup/cf_%d_%s_%p_%T.bkp' tag 'cf_backup_full';
backup spfile format '/backup/pr_%d_%s_%p_%T.bkp' tag 'pr_backup_full';
}
备份顺序不能返(1.database->2.archivelog->3.controlfile->4.spfile)
offline
run{
allocate channel c1 type disk maxpiecesize=20G;
allocate channel c2 type disk maxpiecesize=20G;
sql 'alter system archive log current';
backup database format '/backup/db_%d_%s_%p_%T.bkp' tag 'db_backup_full';
backup current controlfile format '/backup/cf_%d_%s_%p_%T.bkp' tag 'cf_backup_full';
backup spfile format '/backup/pr_%d_%s_%p_%T.bkp' tag 'pr_backup_full';
}
少了archivelog的备份
备份完后查看备份情况
list backup;
offline的恢复(冷备)
startup force nomount;
restore controlfile;
alter database mount;
restore database;
recover database noredo;
alter database open resetlogs;
------------------------------------------------------------------
report schema;列出当前数据库的文件分布
数据文件丢失恢复:
数据库mount模式下:
restore datafile 5;
recovery datafile 5;
alter database open;
控制文件丢失恢复:
shutdown abort;
startup mount;
show parameter control
cp file1 file2
ls -ltr
restore controlfile from autobackup;
或者 restore controlfile from '/back/....';
alter database mount;
recover database;
alter database open resetlogs;
1.good : backup database
2.file 5: restore recover
3.good
4.controlfile error
5.restore controlfile
--------------------------------------------------------------
删除备份
run{
delete force noprompt backup;
delete force noprompt copy;
delete force noprompt archivelog all;
}
delete backupset 13(BS Key);
delete obsolete;
模拟数据库全库删掉整库恢复
查看数据库是否状态正常
select open_mode from v$database;
report schema;
rm -r /orcl/datafile
restore database;
恢复过程中查看IO
iostat 1
asm的好处数据库使用盘读写很均匀 普通文件系统没办法做到
recover database;通过归档日志做前滚
alter database open resetlogs;
数据库server 重启
srvctl stop database -d orcl
srvctl start database -d orcl
数据库恢复至少需要的文件
- controlfile * 1
- system *1
sysaux * 1
- redolog * 2
undo * 1
将临时文件temp datafile删掉。 数据库能正常起来
这些场景会用到temp表空间order by , distinct , union, group by , join (PGA不够时会用到temp表空间)
alter tablespace temp add tempfile '***/' size **M autoextend on next 10M maxsize 8192M;
恢复temp(建temp2并切换,再建temp再切换回temp)
1.create temporary tablespace temp2 tempfile '***/' size **M autoextend on next 10M maxsize 8192M;
2.alter database default temporary tablespace temp2;
3.drop tablespace temp including contents and datafiles;
4.create temporary tablespace temp tempfile '***/' size **M autoextend on next 10M maxsize 8192M;
5.alter database default temporary tablespace temp;
6.drop tablespace temp2 including contents and datafiles;