Oracle 学习笔记: Backup & Recovery 常用命令

1 . set database to archivelog mode

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area  251658240 bytes
Fixed Size                  1248356 bytes
Variable Size              83887004 bytes
Database Buffers          159383552 bytes
Redo Buffers                7139328 bytes
Database mounted.

SQL> alter database archivelog;
Database altered.

SQL> alter database open;
Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1319
Next log sequence to archive   1321
Current log sequence           1321

 

2 . define flash recovery area

SQL> alter system set db_recovery_file_dest='D:\oracle\flash_recovery_area' scope=both;
System altered.
SQL> alter system set db_recovery_file_dest_size=15G scope=both;
System altered.

 

Oracle will use Oracle Managed File (OMF) for the flash recovery area. The free space in recovery area can be checked using OEM: All Metrics -> Recovery Area, or query vflash_recovery_area_usage view. To get more free space, you can use the following command to backup and then delete all the archived log files.

RMAN> backup archivelog all delete all input; 

 

3 . define multiple archived log destinations

SQL> alter system set log_archive_dest_1='location=use_db_recovery_file_dest' scope=both;
System altered.
SQL> alter system set log_archive_dest_2='location=D:\oracle\archivelog_area1' scope=both;
System altered.

 

4 . CONTROL_FILE_RECORD_KEEP_TIME

 

This parameter specify the minimum days the RMAN information is stored in the control file before overwritten. The default value is 7 days. When using catalog, a smaller value should be chosen.

 

5 . starting RMAN

rman target /
rman target / nocatalog
rman target sys/change_on_install@orcl
rman target sys/change_on_install@orcl catalog rman/rman@catdb
rman target sys/change_on_install log=xxx.log append
rman target sys/change_on_install cmdfile=xxx.rcv

 

6 . RMAN persistent settings

 

6.1 display settings

RMAN> show all;
RMAN> show controlfile autobackup;
RMAN> show retention policy;

 

6.2 configure settings

RMAN> configure retention policy to recovery window of 7 days;
RMAN> configure backup optimization on;
RMAN> configure default device type to disk;
RMAN> configure controlfile autobackup on;
RMAN> configure controlfile autobackup format for device type disk to '%F';
RMAN> configure device type disk backup type to compressed backupset parallelism 1;
RMAN> configure datafile backup copies for device type disk to 1;
RMAN> configure archivelog backup copies for device type disk to 1;
RMAN> configure channel device type disk maxpiecesize 1 G;
RMAN> configure maxsetsize to unlimited;
RMAN> configure encryption for database off;
RMAN> configure encryption algorithm 'AES128';
RMAN> configure archivelog deletion policy to none;
RMAN> configure snapshot controlfile name to 'D:\oracle\flash_recovery_area\sncfepcit.ora';

 

If the control file autobackup is enabled, then RMAN automatically backs up the control file and spfile in one of two circumstances:
- A successful backup is recorded in the RMAN repository
- A structural change to the database affects the contents of the control file

Control file autobackups are stored in the flash recovery area, unless otherwise specified.

 

6.3 reset settings to default value

RMAN> configure controlfile autobackup clear;
RMAN> configure retention policy clear;

 

7. RMAN commands

 

7.1 backup commands

RMAN> backup database;
RMAN> backup copy of database;
RMAN> backup as compressed backupset database;
RMAN> backup as backupset format ''/BACKUP/df_%d_%s_%p.bus' tablespace users;
RMAN> backup database plus archivelog delete all input;
RMAN> backup archivelog from sequence=234 delete input;
RMAN> backup tag='month_full_backup' datafile 1, 2, 3, 4;
RMAN> backup incremental level 0 database;
RMAN> backup incremental level 1 database;
RMAN> backup incremental level 1 cumulative database;

RMAN> run {
2> allocate channel c1 device type sbt;
3> allocate channel c2 device type sbt;
4> allocate channel c3 device type sbt;
5> backup incremental level = 0
6> format '/disk1/backup/df_%d_%s_%p.bak'
7> (datafile 1,4,5 channel c1)
8> (datafile 2,3,9 channel c2)
9> (datafile 6,7,8 channel c3);
10> alter system archive log current;
11> }

 

7.2 block change tracking

SQL> alter database enable block change tracking using file ''/mydir/rman_change_track.f' reuse;
SQL> alter database disable block change tracking;

 

7.3 incrementally updating backups

RMAN> backup as copy incremental level 0 datafile 1 tag 'basecopy';
RMAN> backup incremental level 1 for recover of copy with tag 'basecopy' datafile 1;
RMAN> recover copy of datafile 1 with tag 'basecopy';

 

7.4 list commands

RMAN> list backup of database summary;
RMAN> list backup of tablespace system summary;
RMAN> list backup of datafile {n|'file_name'} summary;
RMAN> list backup of database by {file|backup};
RMAN> list copy of database;

 

7.5 report commands

RMAN> report schema;
RMAN> report need backup incremental 0 database;
RMAN> report need backup days 3;
RMAN> report need backup redundancy 2;
RMAN> report need backup recovery window of 3 days;
RMAN> report obsolete redundancy 2;
RMAN> report obsolete recovery window of 3 days;

 

7.6 delete commands

RMAN> delete noprompt expired copy;
RMAN> delete noprompt expired backup;
RMAN> delete noprompt obsolete;
RMAN> delete obsolete redundancy 2;
RMAN> delete obsolete recovery window of 3 days;
RMAN> delete backupset 4;

 

8. RMAN v$ views

V$ARCHIVED_LOG
V$BACKUP_CORRUPTION
V$BACKUP_DEVICE
V$BACKUP_FILES
V$BACKUP_PIECE
V$BACKUP_REDOLOG
V$BACKUP_SET
V$BACKUP_SPFILE
V$COPY_CORRUPTION
V$RMAN_CONFIGURATION

你可能感兴趣的:(oracle,sql,F#,Flash,UP)