Oracle RMAN backup and restore scripts

Oracle RMAN backup and restore scripts

First, backup solutions:
multi-level backup to reduce the recovery time needed for daily backups and reduce the time required, but ensure that the system has a good recovery.
The following is a proposed solution:
  
 every six months to do a full backup of the database (contains a read-only table space)
 to do a zero-level backup of each month (does not include a read-only table space)
 each week to do a backup
 to do a day two backup
 make a backup of the table space after any change read-only table space.
 When needed (e.g., four hours archive system will close full) backup archive file
1, the database full backup script :
RUN {
the allocate Channel C1 Disk type;
Backup Tag Full 'dbfull' the format '/ opt / Backup / full_% D_% U '(Database the include Current controlfile);
SQL' ALTER System Archive log Current ';
backup the format' / opt / backup / archivelog_% D_% U '(ARCHIVELOG All);
Release Channel C1;
}
2, a zero-level backup :
{RUN
the allocate Channel C1 Disk type;
backup incremental level 0 filesperset 5 tag 'dbL0' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
3、一级备份 :
run {
allocate channel c1 type disk;
backup incremental level 1 filesperset 5 tag 'dbL1' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
4、二级备份 :
run {
allocate channel c1 type disk;
backup incremental level 2 filesperset 5 tag 'dbL2' format '/opt/backup/ora_0_%d_%u' (database include current controlfile);
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
5、表空间备份 脚本(以users表空间为例):
run {
allocate channel c1 type disk;
backup  tag 'tsusers' format '/opt/backup/ora_0_%d_%u' tablespace users;
sql 'alter system archive log current' ;
backup format '/opt/backup/archivelog_%d_%u' (archivelog all);
release channel c1;
}
6、归档文件备份 脚本:
run {
allocate channel c1 type disk;
Backup the format '/ opt / Backup / archivelog_% D_% U' (ARCHIVELOG All);
Release Channel C1;
}


two, the RMAN recovery case
1, the loss of all data files, control files, log files must be present
 
   analog media damage: Delete all dbf file
   to start the database: startup mount
   restore statement:
   RUN {
     the allocate Channel c1 of the type Disk;
     restore database;
     recover database;
     SQL 'the ALTER Open database';
     Release Channel c1;
 }
   Note: Oracle is never backed up using the tEMPORARY table space for temporary files, because it is only temporary temporary table space contains the
        property data, you do not have to restore. But after reducing the data dictionary or related information temporary table space, you just
        simply rebuild a temporary table space, set it as the default temporary table space, then the previous temporary table space can be deleted.
   SQL> create temporary tablespace temp2 tempfile ' d: oracleoradataoradbtemp02.dbf' size 100M;
   SQL> the ALTER TABLESPACE temp2 the Temporary Database default;
   SQL> drop the TEMP TABLESPACE Including Contents and the Datafiles;

2, the loss of non-system data file recovery
   analog media damage: Delete files users01.dbf
   start the database: startup mount
   restore statement:
   RUN {
       the allocate Channel c1 of the type Disk;
       SQL 'ALTER TABLESPACE Users Offline';
       restore TABLESPACE Users;
       recover TABLESPACE Users;
       SQL 'ALTER TABLESPACE Users Online';
       Release Channel C1;
 }

. 3, the loss of all data files, the control file, the log file recovery
 
   Note: configuration during backup ON controlfile AutoBackup the Configure;
 
   [Oracle @ Linux1  rman_backup] $ RMAN target /
   the RMAN> = 285 819 149 SET the DBID
   RMAN> restore controlfile from autobackup (may: restore controlfile from 'file name' );
   Start the database: startup mount
   recovery statement:
   RUN {
       the allocate Channel C1 type Disk;
       Restore Database;
       Recover Database;
       SQL 'ALTER Database Open RESETLOGS';
       Release C1 Channel;
    }

. 4, incomplete recovery

a, based on the time point incomplete recovery:
the RUN {
   the ALLOCATE the TYPE DISK the CHANNEL C1;
   the SET the UNTIL the tIME = '2002-12-09:. 11: 44 is: 00';
   the rESTORE DATABASE;
   the rECOVER DATABASE ;
   sql'ALTER the OPEN DATABASE RESESTLOGS ';
   the RELEASE the CHANNEL. 1;
}
B, based on incomplete recovery log sequence:
the RUN {
   ALLOCATE CHANNEL c1 TYPE DISK;
   SET UNTIL SEQUENCE 120 THREAD 1;
   RESTORE DATABASE;
   RECOVER DATABASE; # recovers through log 119
   sql'ALTER DATABASE OPEN RESESTLOGS';
   RELEASE CHANNEL 1;
}
C、基于SCN的不完全恢复:
RUN {
   ALLOCATE CHANNEL c1 TYPE DISK;
   SET UNTIL SCN=100145;
   RESTORE DATABASE;
   RECOVER DATABASE;
   sql'ALTER DATABASE OPEN RESESTLOGS';
   RELEASE CHANNEL 1;
}
D、基于cancel的不完全恢复:
RUN {
   ALLOCATE CHANNEL c1 TYPE DISK;
   RESTORE DATABASE;
   RECOVER DATABASE UNTIL CANCEL;
   SQL'ALTER DATABASE OPEN RESESTLOGS';
   The CHANNEL 1 the RELEASE;
}


Third, maintain RMAN RMAN is divided into several aspects of maintenance
1, see the information RMAN
         Check the existing backup
           RMAN> list backup
         list expired backup
           RMAN> report obsolete
         Delete expired backup
           RMAN> allocate channel for maintenance Disk of the type;
           RMAN> change the delete BACKUPSET the above mentioned id;
           RMAN> Release Channel;
         remove all expired backup
           RMAN> the delete Obsolete;
          
2, synchronization or reset the RMAN
 
        If the target database physical object changes, such as adding a data file, you need to use the following command synchronization:
        RMAN> resync Cataog;
        if the target database reset the database, need to synchronize with the following command
        RMAN> reset database;
      
        when manually delete the database archive file, execute the following script to synchronize
        RMAN> the allocate Channel for Maintenance of the type Disk;
        RMAN> Change ARCHIVELOG All CROSSCHECK;
        RMAN> Release Channel;
      
        when manually delete RMAN backup database to execute the following script to synchronize
        RMAN> the allocate Channel for Maintenance of the type Disk;
        RMAN> CROSSCHECK Backup ;
        RMAN> the Delete expired The Backup;
        RMAN> Release Channel;
     

Reproduced in: https: //my.oschina.net/kivensoft/blog/549373

Guess you like

Origin blog.csdn.net/weixin_33955681/article/details/92058669