Cloning / duplicating with RMAN, the basics
rman可以备份的数据库
target database 生产数据库 reconvery catalog database 目录数据库 auxiliary database 附注数据库
DELETE BACKUP
DELETE BACKUP DEVICE TYPE DISK
非catalog方式备份
全备份
0级增量备份
1级增量备份
[oracle@tlbb ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Feb 5 17:38:01 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> archive log list
Database log mode Archive Mode //在归档状态下
Automatic archival Enabled //
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
SQL>
切换服务器归档模式
$sqlplus /nolog
SQL> conn /as /sysdba (以dba的身分连接DB)
SQL> shutdown immediate; (立即关闭数据库)
SQL> startup mount (启动实例并加载数据库,但不打开)
SQL> alter database archivelog; (更改数据库为归档模式)
SQL> alter database open; (打开数据库)
SQL> alter system archive log start; (启用自动归档)
SQL> exit (退出)
RMAN> connect target / (连接数据库)
connected to target database: TLBB (DBID=1486193478)
RMAN> backup database; (全备份)
RMAN> backup incremental level=0 database; (0级增量备份)
RMAN> backup incremental level=1 database; (1级增量备份)
备份archivelog
backup database plus archivelog delete input;
备份表空间
backup tablespace user(用report schema;查看)
备份控制文件
backup current controlfile;
backup database include current controfile
================================================================================
备份集 backupset
镜像备份 image copies
copy datafile ... to ...
RMAN> copy datafile 4 to '/backup1/users.dbs';
RMAN> list copy;
单命令
backup database;
批命令备份
run {
allocate channel cha1 type disk;
backup
format "/backup1/full_%t"
tag full-backup
database;
release clannel cha1;
}
===================================================
备份计划:
星期天晚上 -level 0
星期一晚上 -level 2
星期二晚上 -level 2
星期三晚上 -level 1
星期四晚上 -level 2
星期五晚上 -level 2
星期六晚上 -level 2
bakl0
run {
allocate channel c1 type disk;
backup
incremental level 0
format "/backup1/inc0_%u_%T"
tag monday_inc0
database;
release channel c1;
}
bakl1
run {
allocate channel c1 type disk;
backup
incremental level 1
format "/backup1/inc1_%u_%T"
tag monday_inc1
database;
release channel c1;
}
bakl2
run {
allocate channel c1 type disk;
backup
incremental level 2
format "/backup1/inc2_%u_%T"
tag monday_inc2
database;
release channel c1;
}
命令:
rman target / msglog=/backup1/bakl0.log cmdfile=/backup/bakl0
crontab -e -u oracle
45 23 * * 0 rman target / msglog=/backup1/bakl0.log cmdfile=/backup/bakl0
45 23 * * 1 rman target / msglog=/backup1/bakl2.log cmdfile=/backup/bakl2
45 23 * * 2 rman target / msglog=/backup1/bakl2.log cmdfile=/backup/bakl2
45 23 * * 3 rman target / msglog=/backup1/bakl1.log cmdfile=/backup/bakl1
45 23 * * 4 rman target / msglog=/backup1/bakl2.log cmdfile=/backup/bakl2
45 23 * * 5 rman target / msglog=/backup1/bakl2.log cmdfile=/backup/bakl2
45 23 * * 6 rman target / msglog=/backup1/bakl2.log cmdfile=/backup/bakl2
分,时,天,月,星期
service crond restart
CONFIGURE CONTROLFILE AUTOBACKUP ON;
自动备份controlfile
delete backupset 11;
delete backupset 1;
删除备份
===================================================================
口令文件丢失(/dbs/orapwherming)
orapwd file=orapwherming password=pass123 entries=5
spfiel丢失(mv ../dbs/spfiletlbb.ora spfiletlbb.bak)
[oracle@tlbb dbs]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Feb 5 19:07:57 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TLBB (DBID=1486193478)
RMAN> shutdown immediate;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
===============================================
RMAN> startup nomount;
RMAN> set dbid 1486193478;
RMAN> restore spfile from autobackup;
RMAN> restore spfile from '/backup1/ctlc-1486193478-20090205-09'; (如果自动不能找到,手工指定)
RMAN> shutdown immediate;
RMAN> startup; (如果不行,先set dbid 1486193478;再startup)
controlfile丢失():
删除/u01/app/oracle/oradata/tlbb目录下*.ctl文件
sqlplus /nolog
conn /as sysdba
shutdown immediate;
shutdown abort;
exit
==================================================
RMAN> startup nomount;
RMAN> restore controlfile from autobackup;
restore controlfile from '/backup1/ctlc-1486193478-20090205-09';
RMAN> alter database mount;
RMAN> recover database;
RMAN> alter database open resetlogs;
redolog file丢失:
删除/u01/app/oracle/oradata/tlbb目录下*.log文件
=================================================
sqlplus /nolog
conn /as sysdba
shutdown immediate;
startup mount;
recover database until cancel;
alter database open resetlogs;
datafile丢失:
删除/u01/app/oracle/oradata/tlbb目录下*.dbf文件
================================================
RMAN> report schema;看ID号:2
sql "alter database datafile 2 offline" ;
sql "alter database datafile 2 offline immediate" ;
restore datafile 2 ;
recover datafile 2 ;
sql "alter database datafile 2 online" ;
表空间丢失:
sql "alter tablespace users offline"
restore tablespace users
recover tablespace users
sql "alter database tablespace users online"
--------------------------------------------------------
非catelog方式完全恢复:
sqlplus /nolog
conn /as sysdba
shutdown abort;
rman target /
startup nomount;
restore controlfile from autobackup;
(restore controlfile from '/backup1/ctlc-1486193478-20090205-09';)
alter database mount;
restore database;
sqlplus /nolog
conn /as sysdba
create pfile from spfile;
cd /u01/app/oracle/product/10.2.0.1/dbs
vi inittlbb.ora
....
*._allow_resetlogs_corruption='TURE'
END
sqlplus /nolog
conn /as sysdba
shutdown immediate;
startup pfile=/u01/app/oracle/product/10.2.0.1/dbs/inittlbb.ora
shutdown immediate;
startup pfile=/u01/app/oracle/product/10.2.0.1/dbs/inittlbb.ora mount
alter database open resetlogs;
exit
recover databses;
alter database open restlogs;
基于时间:
基于SCN的恢复:
startup ount
restore database until scn 643309;
recover database until scn 643309;
alter database open resetlogs;
日志序列SEQUENCCE
report schema
list backup
crosscheck backup
delete
alter database open restlogs;做完这个之后,最好做个备份,要不然。redo log会出问题!
这是学习笔记,可能有点乱,错误之处请指正!
Datagurad archivelog delete
https://www.toadworld.com/platforms/oracle/b/weblog/archive/2014/11/30/deleting-applied-on-standby-archivelogs
How to open a database while restoring and recovering without archivelogs
Recovery with Expired Backup Piece with Net Backup
Following steps is to restore L0 backup on a new server.
1 - As Level 0 backup has been taken at source then move that over to target server along with archivelog backups, init.ora file. 2 - Install oracle software version(same as source) on target server. 3 - start DB instance in nomount at target using init.ora file moved from source db server. --if file structure is diff at target then you would have to edit that in init.ora file accordingly. 4 - Restore controlfile from backup piece moved from sounce backup which has controlfile backup. 5 - Once control file restore is done then mount the target db instance. 6 - Catalog all RMAN backups in RMAN at target using RMAN>catalog start with 'backup location'; 7 - RMAN> restore database; 8 - RMAN> recover database; 9 - SQL> alter database open resetlogs;
Best Practices for backing up an RMAN catalog
MetaLink Note 452529.1:
How to backup of the Recovery Catalog ? Recovery catalog database is just like any other database.This database backup need to be taken every time after the target database backup. You can take Physical backup or Logical backup of the catalog database.You can use RMAN for the backup of the recovery catalog database . Few guideline for recovery catalog database + Run the recovery catalog database in ARCHIVELOG mode so that you can do point-in-time recovery if needed. + Set the retention policy to a REDUNDANCY value greater than 1. + Do not use another recovery catalog as the repository for the backups. + Configure the control file autobackup feature to ON. How to restore and Recover recovery catalog from Backup ? Restoring and recovering the recovery catalog is much like restoring and recovering any other database
ORA-01195
Hi Zerandib, In order to restore online backups, you need all datafiles plus archive logs generated during your online backup window. There is no other way to perform a consistent recovery from online backup without archives. The only way to perform a PIT (Point in time recovery) is from a incomplete recovery. One example to do this is restoring all datafiles, plus archivelogs, and execute the "RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL" statement. Incomplete recovery will not work anymore if you firstly try to perform a complete recovery instead (so you might get the "ORA-01195" either from doing this, or from a missing archivelog during your recovery). Personally I would try to do recover one more time from scratch. If it fails again due missing archives, There is a way to "force" opening your database even with missing archives, setting the "_ALLOW_RESETLOGS_CORRUPTION=TRUE" parameter in your init<sid>.ora file. This will allow to open database without performing a consistency check, but attention - Oracle does not guarantee your database consistency after setting this parameter. Check Oracle alert file after doing this to check the side effects. I was able to recover a database once using this param because only the UNDO tablespace was corrupted. After recreating UNDO tablespace, the issue was cleared. Hope it helps. Regards Marcelo Macedo
RMAN scripts
RMAN> create script backup_DDTEST_full
comment 'DDTEST FULL'
{
ALLOCATE CHANNEL C1 TYPE 'SBT_TAPE' TRACE 5 PARMS 'BLKSIZE=1048576, SBT_LIBRARY=/u01/app/oracle/product/11.2.0/db_1/lib/libddobk.so,ENV=(STORAGE_UNIT=ddboost01,BACKUP_HOST=192.168.25.112)';
backup incremental level 0 filesperset 8 database format 'Lev0_%d_%t_%u_%s_%p' plus archivelog;
backup current controlfile format '%d_%t_%u_%s_%p_controlfile.cf';
RELEASE CHANNEL C1;
}
created script backup_DDTEST_full
RMAN>
RMAN> list script names;
List of Stored Scripts in Recovery Catalog
Scripts of Target Database DDTEST
Script Name
Description
-----------------------------------------------------------------------
backup_DDTEST_full
DDTEST FULL
run { execute script
backup_ts_any using 'SYSTEM'; }
Maintaining the RMAN repository For Netbackup
allocate channel for maintenance type 'SBT_TAPE'; crosscheck backupset of database; DELETE OBSOLETE; DELETE OBSOLETE RECOVERY WINDOW OR 7 DAYS; delete expired backupset of database;
Troubleshooting
11.2 RMAN Block recovery syntax
BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL; VALIDATE DATAFILE 3 BLOCK 2412977;
========================= In 11.2 you can use RMAN to: 1) validate all database files and archived redo log files for physical and logical corruption: BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL; 2) to check individual data blocks, as shown in the following example: VALIDATE DATAFILE 4 BLOCK 10 TO 13; 3) validate backup sets: VALIDATE BACKUPSET 3; You specify backup sets by primary key, which is shown in the output of the LIST BACKUP command. The following RMAN command recovers the corrupted blocks: 1) recover all corrupted blocks reported in v$database_block_corruption RMAN> RECOVER CORRUPTION LIST; 2) recover individual blocks, see eg: RMAN> RECOVER DATAFILE 1 BLOCK 233, 235 DATAFILE 2 BLOCK 100 TO 200;
Open Resetlogs Reports Errors ORA-00313 and ORA-00312 to Alert
These messages are informational and occur because the online redo log files do not exist. This is expected behavior and will occur whenever a database is opened in an environment which does not have existing online redo log files.
Note, this will also occur with the RMAN duplicate as it will always have to create new online log files on the database open.
Messages are informational and as long as Oracle is able to create the online redo log files, no action is required.
sql> connect / as sysdba sql> startup mount sql> recover database until cancel; (cancel immediately) sql> alter database open resetlogs;
RMAN-06556
RMAN-03002: failure of recover command at 04/19/2008 13:21:32 RMAN-06556: datafile 1 must be restored from backup older than scn 5965106363950
If you have a good RMAN backup and you only lost your current redo log, then you'll lose any data in that log, but you should still be able to recover.
Startup mount your database and perform the following query:
Code: [Select all] [Show/ hide]
SQL> select group#, first_change#, status, archived from v$log;
At this point, you should be able to perform the following in RMAN:
Code: [Select all] [Show/ hide]
RMAN> run {
restore database;
recover database until scn <scn_from_current_log_above>;
}
RMAN> alter database open resetlogs;
ORA-00354: Corrupt redo log block header tips
http://www.dba-oracle.com/t_ora_00354_corrupt_redo_log_block_header.htm
