Oracle 11g Backup Database with Rman

Source: Internet
Author: User
Tags sqlplus



Using Oracle's own backup recovery tool, Rman (Recovery Manager) has several advantages:


    • Support for incremental backups

    • Ability to automatically manage backup files

    • Automated backup and Recovery

    • File validity Check for backups





Configuring the Flash Recovery Zone (recovery area)



The Flash recovery area is the store where backup and recovery data files and related information are stored. You need to set two parameters: Db_recovery_file_dest_size (maximum capacity of the flash recovery area), Db_recovery_file_dest (the path where the Flash recovery area is located).



To view the Flash recovery area information:


SQL> show parameter db_recovery_file_dest;
NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest     string /data/app/oracle/recovery_area
db_recovery_file_dest_size     big integer 3882M


To modify the Flash recovery area size:


SQL> alter system set db_recovery_file_dest_size=2g;
System altered.
SQL> show parameter db_recovery_file_dest;
NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest     string /data/app/oracle/recovery_area
db_recovery_file_dest_size     big integer 2G


To view usage status:


SQL> select name,space_limit,space_used,number_of_files from v$recovery_file_dest;
NAME
--------------------------------------------------------------------------------
SPACE_LIMIT SPACE_USED NUMBER_OF_FILES
----------- ---------- ---------------
/data/app/oracle/recovery_area
 2147483648     0     0


Display is not used.



You can also use this command to view more information:


Sql> Select File_type,percent_space_used,percent_space_reclaimable,number_of_files from V$flash_recovery_area_ Usage





Establishing an Rman-to-database connection



Create an Rman user, and authorize:


[[email protected] oracle]$ sqlplus /nolog
SQL>  connect/as sysdba
Connected.
SQL> create user rman identified by oracle;
User created.
SQL> grant resource,connect,dba to rman;
Grant succeeded.
SQL> quit


To log in to Rman using Rman users:


[[email protected] oracle]$ rman target rman/oracle
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Nov 3 16:59:27 2017
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1486802665)
RMAN>


You can also log in using the following methods:


[[email protected] oracle]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Nov 3 17:00:35 2017
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
RMAN> connect target system/rman
connected to target database: ORCL (DBID=1486802665)
RMAN> connect target rman/oracle


You can also connect Rman using the operating system authentication:


[[email protected] oracle]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Nov 3 17:02:52 2017
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1486802665)
RMAN>





Configuring Rman



To view the configuration parameters for Rman:


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 ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/data/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f‘; # default


Parameter meaning:



CONFIGURE RETENTION POLICY to redundancy 1



The number of backup copies reserved, which means that only one copy of the data file is kept and the most recent backup copy is kept.



CONFIGURE DEFAULT DEVICE TYPE to DISK



The data file is backed up to disk by default, or it can be another device such as tape (SBT)



CONFIGURE BACKUP Optimization OFF



Without backup optimization, the effect of enabling backup optimization is that if you have backed up the same version of a file, you will no longer back up the file. , keep only one copy of the backup file.



CONFIGURE Controlfile autobackup OFF



Do not start automatic backup of control files, after modification to on, if the database structure changes or in the backup database process, the control file will be automatically backed up to the specified directory



CONFIGURE DEVICE type DISK PARALLELISM 1 BACKUP type to BACKUPSET



The number of backup channels is 1, the default way to use backup sets. The greater the number of channels, the shorter the task time is performed.






If you want to modify the parameters, you can execute the following command:



To turn on backup optimization:


RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored


Set the backup type to copy, which is the image mode:


RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;                          
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1;
new RMAN configuration parameters are successfully stored


Back up the control file to the Flash recovery area:


RMAN> backup current controlfile;
Starting backup at 03-NOV-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/data/app/oracle/recovery_area/ORCL/controlfile/o1_mf_TAG20171103T180113_dzrhm9vk_.ctl tag=TAG20171103T180113 RECID=3 STAMP=959104874
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 03-NOV-17


If you do not specify a flash recovery area, you can also specify the path manually:



Change the flash recovery area to the test directory


SQL> connect/as sysdba
Connected.
SQL> show parameter db_recovery_file_dest;
NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest     string /data/app/oracle/recovery_area
db_recovery_file_dest_size     big integer 2G
SQL> alter system set db_recovery_file_dest=‘/data/app/oracle/test‘;

System altered.

SQL> show parameter db_recovery_file_dest;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest		     string	 /data/app/oracle/test
db_recovery_file_dest_size	     big integer 2G


Configure the disk type and backup directory for the control file backup, and the path ends with%f:


RMAN> configure controlfile autobackup format for device type disk to ‘/data/app/oracle/test/%F‘;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/data/app/oracle/test/%F‘;
new RMAN configuration parameters are successfully stored





Rman Offline backup



Rman offline backup requires shutting down the database and starting the database into Mount state.


[[email protected] oracle]$ sqlplus /nolog
SQL> connect/as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1586708480 bytes
Fixed Size		    2213736 bytes
Variable Size		  939526296 bytes
Database Buffers	  637534208 bytes
Redo Buffers		    7434240 bytes
Database mounted.
SQL> quit


Go to Rman and back up your data:



View the default parameters for data backup, Backup mode (copy or backupset), and backup format (disk or other)


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 ON;
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 BACKUP TYPE TO COPY PARALLELISM 1;
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 ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/data/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f‘; # default


To perform a backup command using copy mode, the image replicates the entire library:


rman> backup as Copy database;


If you are using the default backupset mode, you can use:


Rman> Backup as compressed backupset database;


After the backup is complete, open the database:


rman> SQL ' ALTER DATABASE open '; SQL Statement:alter database Open





Rman backs up the entire database online



The online backup must have a flash recovery area set up, the flash recovery area to be large enough, and the database to be placed in archive mode. While the database is being backed up, DML operations can be performed, read normally, and the new DML operations record will be in the Redo log file, if the backup time is long and there is a large amount of data changes during this period, the redo log switches to write the changed data to the archive log file. The archive log here is similar to MySQL's Binlog, which uses backup and archive logging and complete recovery of the data in the event of a media failure.



Check to see if the database archiving mode is on and is currently off:


SQL> archive log list;
Database log mode       No Archive Mode
Automatic archival       Disabled
Archive destination       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     22
Current log sequence       24


Turn on log archiving:


SQL> alter database archivelog;
alter database archivelog
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any
instance


Log archive must be in Mount mode, turn off database boot to mount mode, turn on archive mode:


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

SQL> startup mount;
ORACLE instance started.
Total System Global Area 1586708480 bytes
Fixed Size    2213736 bytes
Variable Size 1040189592 bytes
Database Buffers  536870912 bytes
Redo Buffers    7434240 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     22
Next log sequence to archive   24
Current log sequence       24


To back up the database using Rman online:


Rman> Backup as compressed backupset database plus archivelog Delete all input;


Use Backup set format for backup, and compress in a manner of approximately 5:1. Back up the data files, and also back up the archived log files, after which the archived log files that have been backed up are removed from the storage directory and the archive space is cleared.



Backup table Space:


RMAN> backup tablespace users;
Starting backup at 06-NOV-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/data/app/oracle/oradata/orcl/users01.dbf
output file name=/data/app/oracle/test/ORCL/datafile/o1_mf_users_dzzxzmxv_.dbf tag=TAG20171106T134939 RECID=12 STAMP=959348980
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 06-NOV-17


Using compression:


Rman> Backup as compressed backupset tablespace users;


Using Rman to back up data files,%u indicates that a unique name is automatically assigned:


Rman> Backup as backupset datafile 1 format '/data/app/backup/datafile_1_%u ';


Clear command, use with caution



To clear the old backup file set format:


RMAN>  delete obsolete; 
RMAN> crosscheck backupset;
RMAN> delete expired backupset;


Clear the old backup file and all backups, copy mode:


RMAN>  list datafilecopy all;
RMAN> delete expired backupcopy;
RMAN> crosscheck datafilecopy all;
RMAN> delete expired backupcopy;


If this is due to the Flash recovery area capacity limit, you can modify the path and capacity of the flash recovery area:


Sql> alter system set db_recovery_file_dest= '/data/app/oracle/test ';
Sql> alter system set db_recovery_file_dest_size=10g;


Rman Incremental Backup



When you use Backup database, it is a full-library backup, which is time-consuming and disk-intensive, and an incremental backup of Rman can solve these problems.



There are two levels of backup, Level 0 backup is a full-library backup, Level 1 backup is an incremental backup, and generally requires a 0-level backup of the data after a Level 1 incremental backup.


Rman> Backup incremental level 0 database;


Differential incremental backup of Level 1:


Rman> Backup incremental level 1 database;





Incremental backup of an image copy


RMAN> run {     
2> backup incremental level 1 for recover of copy with tag ‘incr_copy_backup‘ database;
3> recover copy of database with tag ‘incr_copy_backup‘;
4> }


Each time you execute this command, you can use an image to make an incremental backup of the database.









This article is from the "Trying" blog, make sure to keep this source http://tryingstuff.blog.51cto.com/4603492/1979382



Oracle 11g Backup Database with Rman


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.