Oracle 11g R2 rac rman backup script example
1. Switch RAC to archive Mode
1. Modify the archive mode of the database. Generally, archive is configured and the flash back area is used when RAC is installed. you can skip the steps below if you have configured archive.
SQL> alter system set cluster_database = false scope = spfile sid = '*';
2. Shut down all instances (shutdown on both sides)
SQL> shutdown immediate
Or directly close all instances.
$ Srvctl stop database-d orcl
3. Start the database to the mount state on any instance and modify the database archive mode.
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter system set cluster_database = true scope = spfile sid = '*';
SQL> shutdown immediate;
4. Start all instances
$ Srvctl start database-d orcl
5. Verify that archive mode is enabled
SQL> archive log list;
2. Configure the NFS shared directory to store RMAN backup data
1. Configure the nfs service to ensure that both sides of the Backup directory can be accessed. Test here and use node 1 to provide the nfs service.
Node1 Configuration:
# Cat/etc/exports
# It indicates that node 2 is also mounted to the node's RMAN backup directory.
/Data/rman_bak db2 (rw, no_root_squash)
2. Configure node2 and use node 2 as the nfs client. The two directories are consistent.
# Manual mounting
# Mount-t nfs db1:/data/rman_bak
# Configure automatic mounting upon startup
# Cat/etc/fstab
Db1:/data/rman_bak nfs defaults 0 0
Iii. Oracle 11g RAC database Parameter Modification
1. Modify the backup time of the control file
Note: The default value is 7 days, which can be modified as needed.
SQL> show parameter control;
SQL> alter system set control_file_record_keep_time = 40 scope = both;
2. RMAN configuration parameters
When automatic backup of control files is enabled, control files and spfile files are automatically backed up when database backup or data files (such as adding data files) are modified.
RMAN> configure controlfile autobackup on;
RMAN> configure retention policy to recovery window of 30 days;
3. Backup Policy
Make sure that the database runs in archive mode and backs up the database once a day. You can determine the storage backup time based on the disk space on the backup server and the custom policy.
Perform Level 0 backup every Sunday
Perform Level 1 backup every Monday, two, three, four, five, and six.
Iv. RMAN backup script configuration
1. Prepare the Directory
# Su-oracle
Note: You can create related directories based on the actual situation. Pay attention to the directory permissions.
$ Mkdir-p/u01/app/oracle/rman_bak/scripts
$ Mkdir-p/data/rman_bak/data
$ Mkdir-p/data/rman_bak/logs
NOTE: If ASM is used for RAC backup, the backup can only be performed on one node. That is to say, this backup is stored on one of the nodes, and other nodes can be restored by using NFS.
2. Create script content
$ Vi/u01/app/oracle/rman_bak/scripts/rman_bak.sh
$ Chmod u + x/u01/app/oracle/rman_bak/scripts/rman_bak.sh
3. Add a scheduled task
$ Crontab-e
# RMAN
00 1 ** 0/u01/app/oracle/rman_bak/scripts/rman_bak.sh 0
00 1 ** 1, 2, 3, 4, 5, 6/u01/app/oracle/rman_bak/scripts/rman_bak.sh 1
4. Manual test Channel
Manually add db1 and db2 local service name configuration. By default, 11g rac only has servers with scan ip addresses. The local service name must be manually added as follows:
# Su-oracle
$ Vi/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames. ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = scan-cluster) (PORT = 1521 ))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = db1-vip) (PORT = 1521 ))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(INSTANCE_NAME = orcl1)
)
)
ORCL2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = db2-vip) (PORT = 1521 ))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(INSTANCE_NAME = orcl2)
)
)
Manual test Channel
Rman target/
Configure channel 1 device type disk connect 'sys/oracle123 @ orcl1 ';
Configure channel 2 device type disk connect 'sys/oracle123 @ orcl2 ';
4. Script deployment plan
$ Vi/u01/app/oracle/rman_bak/scripts/rman_bak.sh
#! /Bin/bash
Export ORACLE_BASE =/u01/app/oracle
Export ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1
Export ORACLE_SID = orcl1
Export NLS_LANG = AMERICAN_AMERICA.ZHS16GBK
Export PATH = $ ORACLE_HOME/bin: $ PATH
LEVEL =$ @
DATE = 'date + % W'
DATE_2 = 'date + % Y % m % d'
BACKUP_PATH = "/data/rman_bak"
BIN = $ ORACLE_HOME/bin
If [$ #! = 1]; then
Echo "usage: rman_bak.sh n
Where n is the rman backup level (Only 0, 1 is permitted )."
Exit 1
Fi
If [$ @-ne 0-a $ @-ne 1]; then
Echo "usage: rman_bak.sh n
Where n is the rman backup level (Only 0, 1 is permitted )."
Exit 2
Fi
If [[$ LEVEL = 0]; then
$ BIN/rman log $ BACKUP_PATH/logs/level. $ ORACLE_SID. $ LEVEL. $ DATE_2.log <EOF
Connect target /;
Run {
Allocate channel c1 device type disk connect 'sys/oracle @ orcl1 ';
Allocate channel c2 device type disk connect 'sys/oracle @ orcl2 ';
Crosscheck backupset of archivelog all;
Backup archivelog all format' $ BACKUP_PATH/data/archlog. % d. level. $ LEVEL. % U _ % t' delete all input;
Delete noprompt expired backupset of archivelog all;
Release channel c1;
Release channel c2;
}
Run {
Allocate channel c1 device type disk connect 'sys/oracle @ orcl1 ';
Allocate channel c2 device type disk connect 'sys/oracle @ orcl2 ';
Crosscheck backupset of database;
Backup incremental level $ LEVEL database format' $ BACKUP_PATH/data. % d. level. $ LEVEL. % U _ % T ';
Backup spfile tag = 'spfile' format' $ BACKUP_PATH/data/spfile _ % U _ % T ';
Backup current controlfile tag = 'control' format = '$ BACKUP_PATH/data/control _ % U _ % T ';
Delete noprompt expired backupset of database;
Delete noprompt obsolete;
Release channel c1;
Release channel c2;
}
Exit;
EOF
Else
$ BIN/rman log $ BACKUP_PATH/logs/level. $ ORACLE_SID. $ LEVEL. $ DATE_2.log <EOF
Connect target /;
Run {
Allocate channel c1 device type disk connect 'sys/oracle @ orcl1 ';
Allocate channel c2 device type disk connect 'sys/oracle @ orcl2 ';
Crosscheck backupset of archivelog all;
Backup archivelog all format' $ BACKUP_PATH/data/archlog. % d. level. $ LEVEL. % U _ % t' delete all input;
Delete noprompt expired backupset of archivelog all;
Release channel c1;
Release channel c2;
}
Run {
Allocate channel c1 device type disk connect 'sys/oracle @ orcl1 ';
Allocate channel c2 device type disk connect 'sys/oracle @ orcl2 ';
Crosscheck backupset of database;
Backup incremental level $ LEVEL database format' $ BACKUP_PATH/data. % d. level. $ LEVEL. % U _ % T ';
Backup spfile tag = 'spfile' format' $ BACKUP_PATH/data/spfile _ % U _ % T ';
Backup current controlfile tag = 'control' format = '$ BACKUP_PATH/data/control _ % U _ % T ';
Delete noprompt expired backupset of database;
Delete noprompt obsolete;
Release channel c1;
Release channel c2;
}
Exit;
EOF
Fi
5. manually execute the test
$/U01/app/oracle/rman_bak/scripts/rman_bak.sh 0
Test notes:
1) check whether the rman log has any exception or error.
2) Check whether archivelog has been backed up and deleted.
Oracle Database rman backup plan and recovery
Oracle RMAN implements "one-click" tablespace TSPITR
Oracle 11gR2 uses RMAN to copy full-database records
RMAN: Configure an archive log deletion policy
Basic Oracle tutorial-copying a database through RMAN
Reference for RMAN backup policy formulation
RMAN backup learning notes
Oracle Database Backup encryption RMAN Encryption