备份恢复
配置可恢复性
控制文件:通过增加镜像进行备份
SQL> show parameter control_files
SQL> select * from v$controlfile;
修改路径:
$ cd $ORACLE_HOME/dbs
$ ls //查看一下
$ cp spfileorcl.ora spfileorcl.ora.bak // 备份
以Sys用户身份 2步: 改参数 ---移动位置
SQL>alter system set control_files='/u01/app/oracle/oradata/orcl/control01.ctl',
'/home/oracle/control02.ctl' 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;
增加镜像: (至少2份) 2步: 改参数 ---移动位置
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
数据文件 :定时备份和2个定时备份之间做归档
开启归档模式:
SQL> archive log list 检查当前设置
SQL> shutdown immediate
SQL> startup mount //只打开到mount阶段
SQL> alter database archivelog; //修改为归档模式
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配置
Rman用途
在数据库中,RMAN代表Recovery Manager。
RMAN可以用来备份和还原数据库文件、归档日志和控制文件。它也可以用来执行完全或不完全的数据库恢复。
注意:RMAN不能用于备份初始化参数文件和口令文件。
RMAN启动数据库上的Oracle服务器进程来进行备份或还原。备份、还原、恢复是由这些进程驱动的。
RMAN可以由OEM的Backup Manager GUI来控制。
RMAN 的备份和恢复级别分为:数据库级别、表空间级别、文件级别。
RMAN有2种方式:1.控制文件方式 2.Catalog方式。
RMAN的具体备份形式也分2种:1.Image copy 2.backup。
配置:
$ rman target / 或rman target sys/password@orcl
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 compressed backupset tablespace users;
RMAN> backup as copy tablespace users;
RMAN> list backup of tablespace users;
RMAN> list copy of tablespace users;
备份的加密: