恢复
误操作管理员利用备份(老式方法)或者闪回(快捷灵活,可单独闪回某张表)进行回复
rman物理恢复
完全恢复(介质故障)
不完全恢复(用户误操作)
oracle三种重要文件
控制文件
日志文件
数据文件
配置可恢复性
控制文件
SQL> show parameter control_files
SQL> select * from v$controlfile;
修改路径:
$ cd $ORACLE_HOME/dbs
$ cp spfileorcl.ora spfileorcl.ora.bak //参数文件,重要,损坏后无法启动数据库
SQL> alter system set control_files=‘/u01/app/oracle/oradata/orcl/control01.ctl‘, ‘/home/oracle/control02.ctl‘ scope=spfile;//一个文件对应一对‘‘ ,同时修改参数为静态参数,因此scope=spfile
SQL> shutdown immediate//静态参数修改生效需重启
$ mv /u01/app/oracle/fast_recovery_area/orcl/control02.ctl /home/oracle/control02.ctl
SQL> startup
SQL> show parameter control_files
SQL> select * from v$controlfile;
增加镜像:
SQL> alter system set control_files=‘/u01/app/oracle/oradata/orcl/control01.ctl‘, ‘/home/oracle/control02.ctl‘, ‘/home/oracle/control03.ctl‘ scope=spfile;
SQL> shutdown immediate
$ cp /home/oracle/control02.ctl /home/oracle/control03.ctl
SQL> startup
SQL> show parameter control_files
SQL> select * from v$controlfile;
日志文件:
增加成员和日志组:
SQL> select GROUP#, SEQUENCE#, STATUS, MEMBERS from v$log;
SQL> select GROUP#, MEMBER from v$logfile;
SQL> alter database add logfile member ‘/home/oracle/redo01b.log‘ to group 1;
SQL> alter database add logfile member ‘/home/oracle/redo02b.log‘ to group 2;
SQL> alter database add logfile member ‘/home/oracle/redo03b.log‘ to group 3;
SQL> alter database add logfile group 4 (‘/u01/app/oracle/oradata/orcl/redo04.log‘, ‘/home/oracle/redo04b.log‘) size 50M;//创建新的日志
FRA:
SQL> show parameter db_recovery
backupset: 10GB, archived log: 5GB
10+5, 10G
开启归档模式:
SQL> archive log list 检查当前设置
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;// 启用归档模式
alter database noarchivelog;// 关闭归档模式
show parameter db_rec
SQL> alter database open;
SQL> archive log list
SQL> show parameter log_archive_dest //
SQL> select group#, sequence#, status, archived from v$log;
SQL> alter system switch logfile;//手动切换日志
SQL> select group#, sequence#, status, archived from v$log;//查看日志
SQL> select NAME, SEQUENCE#, STATUS from v$archived_log;//查看归档日志
$ ls /u01/app/oracle/fast_recovery_area/ORCL;//查看归档日志
RMAN配置
targedatabase 目标数据库
recovery catalog database 目标目录文件数据库//记录对目标数据库操作记录
注: 若没有目标目录文件数据库 则会将记录存放在目标数据库的控制文件中
channel 通道 备份文件存放路径
recovery manager 客户端
$ rman target / 或rman target sys/[email protected]
RMAN> show all;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP On; //当控制文件有变动时备份会将控制文件一同备份,比如添加了新表空间,信息将写入注册文件,不备份控制文件将有问题。必选
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP clear;
RMAN> backup tablespace users;//备份表空间
RMAN> list backup;
SQL> desc v$backup_set 浏览器中也可以查看
自动通道管理:
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2;//设置多并行通道
RMAN> backup tablespace users, example;
$ mkdir /home/oracle/disk1 /home/oracle/disk2
RMAN> configure channel 1 device type disk to destination ‘/home/oracle/disk1‘;
RMAN> configure channel 2 device type disk to destination ‘/home/oracle/disk2‘;
RMAN> backup tablespace users, example;
恢复默认
RMAN> CONFIGURE DEVICE TYPE DISK clear;
RMAN> CONFIGURE CHANNEL 1 device type disk clear;
RMAN> CONFIGURE CHANNEL 2 device type disk clear;
手动通道管理:
RMAN> run {
allocate channel c1 device type disk to destination ‘/home/oracle/disk1‘;
allocate channel c2 device type disk to destination ‘/home/oracle/disk2‘;
backup tablespace users, example;
或
backup (tablespace users channel c1)(tablespace example channel c2);
}
backup section size 500M datafile 1;
指定备份格式:
RMAN> backup tablespace users; //选用默认
RMAN> backup as backupset tablespace users; //只打包不压缩 默认
RMAN> backup as compressed backupset tablespace users;//打包并且压缩
RMAN> backup as copy tablespace users; //镜像备份
RMAN> list backup of tablespace users; //查看
RMAN> list copy of tablespace users;