oracle数据库恢复与备份
一、oracle数据库恢复
1.恢复刚才删除的一条数据
delete from emp e where e.empname='SMITH'
select * from flashback_transaction_query f where f.table_name='EMP'
UNDO_SQL下面的语句为刚才删除数据的相反操作,执行该语句即可恢复刚才删除的数据
在11g版本中UNDO_SQL为空值
alter database add supplemental log data
2.恢复刚更新的数据到某一时间点
update emp e set e.job='clerk'
select sysdate from dual;
查看指定时间点时的数据是否是需要恢复前的数据:
select * from emp as of timestamp to_timestamp('2013/3/30 21:10:19', 'yyyy-mm-dd hh24:mi:ss')
alter table emp enable row movement;
恢复到某一时间点:
flashback table emp to timestamp to_timestamp('2013/3/30 21:10:19', 'yyyy-mm-dd hh24:mi:ss')
3.恢复删除的表
drop table bonus
flashback table bonus to before drop
查看被删除的表:
select * from user_recyclebin u order by u.droptime desc
二、oracle数据库备份
1.数据库的RMAN备份须要在归档模式下
查看归档模式
$ sqlplus / as sysdba
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 18
Current log sequence 20
更改归档模式
关闭数据库
SQL> shutdown immediate
启动数据库到mount状态
SQL> startup mount
更改为归档模式(noarchivelog为非归档模式)
SQL> alter database archivelog;
再次查看是否为归模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 18
Next log sequence to archive 20
Current log sequence 20
进入RMAN
$ rman target/
查看默认设置
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # defau