转载

【RMAN】RMAN备份恢复1 RMAN冷备脚本与crontab计划任务

RMAN备份恢复1
RMAN冷备脚本与crontab计划任务


冷备(一致性备份,需要关库。非归档模式只能冷备)

SYS@PROD>select version from v$instance;

VERSION
-----------------
11.2.0.3.0




【创建目录】
创建rman冷备目录
[oracle@rhel64 ~]$ mkdir -p /u01/app/oracle/backup/rman_cold

创建备份脚本目录
[oracle@rhel64 ~]$ mkdir -p /u01/app/oracle/scripts


【配置rman】

[oracle@rhel64 ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Thu May 5 12:52:56 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=321736713)

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PROD 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 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD.f'; # default



配置备份冗余度2
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored

开启备份优化
RMAN> CONFIGURE BACKUP OPTIMIZATION on;

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

开启控制文件自动备份
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

RMAN>



RMAN> show all;

RMAN configuration parameters for database with db_unique_name PROD are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
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 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD.f'; # default

RMAN>



【执行rman冷备测试】  连续执行3次 验证删除过时备份命令

run{
shutdown immediate;
startup mount;
crosscheck backup;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup database format '/u01/app/oracle/backup/rman_cold/db_%d_%T_%U.bak';
backup current controlfile format '/u01/app/oracle/backup/rman_cold/control_%d_%T_%U.bak';
alter database open;
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
}



RMAN> run{
2> shutdown immediate;
3> startup mount;
4> crosscheck backup;
5> allocate channel c1 device type disk;
6> allocate channel c2 device type disk;
7> backup database format '/u01/app/oracle/backup/rman_cold/db_%d_%T_%U.bak';
8> backup current controlfile format '/u01/app/oracle/backup/rman_cold/control_%d_%T_%U.bak';
9> alter database open;
10> report obsolete device type disk;
11> delete noprompt obsolete device type disk;
12> delete noprompt expired backup device type disk;
13> release channel c1;
14> release channel c2;
15> }

database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     521936896 bytes

Fixed Size                     2229944 bytes
Variable Size                373295432 bytes
Database Buffers             142606336 bytes
Redo Buffers                   3805184 bytes

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
specification does not match any backup in the repository

released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=18 device type=DISK

allocated channel: c2
channel c2: SID=19 device type=DISK

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
channel c1: starting piece 1 at 05-MAY-16
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
channel c2: starting piece 1 at 05-MAY-16
channel c2: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak tag=TAG20160505T140017 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:26
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak tag=TAG20160505T140017 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:37
Finished backup at 05-MAY-16

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0nr4r38m_1_1.bak tag=TAG20160505T140054 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-MAY-16

Starting Control File and SPFILE Autobackup at 05-MAY-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05 comment=NONE
Finished Control File and SPFILE Autobackup at 05-MAY-16

database opened

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
no obsolete backups found

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
no obsolete backups found

specification does not match any backup in the repository

released channel: c1

released channel: c2

RMAN>






[oracle@rhel64 rman_cold]$ ls -lh
total 1.1G
-rw-r----- 1 oracle oinstall 9.4M May  5 14:00 control_PROD_20160505_0nr4r38m_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:00 db_PROD_20160505_0lr4r37i_1_1.bak
-rw-r----- 1 oracle oinstall 424M May  5 14:00 db_PROD_20160505_0mr4r37h_1_1.bak
[oracle@rhel64 rman_cold]$






【第二次执行】


RMAN> run{
2> shutdown immediate;
3> startup mount;
4> crosscheck backup;
5> allocate channel c1 device type disk;
6> allocate channel c2 device type disk;
7> backup database format '/u01/app/oracle/backup/rman_cold/db_%d_%T_%U.bak';
8> backup current controlfile format '/u01/app/oracle/backup/rman_cold/control_%d_%T_%U.bak';
9> alter database open;
10> report obsolete device type disk;
11> delete noprompt obsolete device type disk;
12> delete noprompt expired backup device type disk;
13> release channel c1;
14> release channel c2;
15> }

database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     521936896 bytes

Fixed Size                     2229944 bytes
Variable Size                373295432 bytes
Database Buffers             142606336 bytes
Redo Buffers                   3805184 bytes

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak RECID=21 STAMP=911052018
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak RECID=22 STAMP=911052018
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0nr4r38m_1_1.bak RECID=23 STAMP=911052055
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05 RECID=24 STAMP=911052056
Crosschecked 4 objects


released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=18 device type=DISK

allocated channel: c2
channel c2: SID=19 device type=DISK

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
channel c1: starting piece 1 at 05-MAY-16
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
channel c2: starting piece 1 at 05-MAY-16
channel c2: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak tag=TAG20160505T140205 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:26
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak tag=TAG20160505T140205 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:36
Finished backup at 05-MAY-16

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0rr4r3c1_1_1.bak tag=TAG20160505T140241 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-MAY-16

Starting Control File and SPFILE Autobackup at 05-MAY-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06 comment=NONE
Finished Control File and SPFILE Autobackup at 05-MAY-16

database opened

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           23     05-MAY-16        
 Backup Piece       23     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0nr4r38m_1_1.bak

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           23     05-MAY-16        
 Backup Piece       23     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0nr4r38m_1_1.bak
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0nr4r38m_1_1.bak RECID=23 STAMP=911052055
Deleted 1 objects


specification does not match any backup in the repository

released channel: c1

released channel: c2

RMAN>




[oracle@rhel64 rman_cold]$ ls -lh
total 2.2G
-rw-r----- 1 oracle oinstall 9.4M May  5 14:02 control_PROD_20160505_0rr4r3c1_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:00 db_PROD_20160505_0lr4r37i_1_1.bak
-rw-r----- 1 oracle oinstall 424M May  5 14:00 db_PROD_20160505_0mr4r37h_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:02 db_PROD_20160505_0pr4r3au_1_1.bak
-rw-r----- 1 oracle oinstall 424M May  5 14:02 db_PROD_20160505_0qr4r3at_1_1.bak
[oracle@rhel64 rman_cold]$




【第三次执行】


RMAN> run{
2> shutdown immediate;
3> startup mount;
4> crosscheck backup;
5> allocate channel c1 device type disk;
6> allocate channel c2 device type disk;
7> backup database format '/u01/app/oracle/backup/rman_cold/db_%d_%T_%U.bak';
8> backup current controlfile format '/u01/app/oracle/backup/rman_cold/control_%d_%T_%U.bak';
9> alter database open;
10> report obsolete device type disk;
11> delete noprompt obsolete device type disk;
12> delete noprompt expired backup device type disk;
13> release channel c1;
14> release channel c2;
15> }

database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     521936896 bytes

Fixed Size                     2229944 bytes
Variable Size                373295432 bytes
Database Buffers             142606336 bytes
Redo Buffers                   3805184 bytes

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak RECID=21 STAMP=911052018
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak RECID=22 STAMP=911052018
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05 RECID=24 STAMP=911052056
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak RECID=25 STAMP=911052125
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak RECID=26 STAMP=911052126
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0rr4r3c1_1_1.bak RECID=27 STAMP=911052162
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06 RECID=28 STAMP=911052163
Crosschecked 7 objects


released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=18 device type=DISK

allocated channel: c2
channel c2: SID=19 device type=DISK

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
channel c1: starting piece 1 at 05-MAY-16
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
channel c2: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0tr4r3gf_1_1.bak tag=TAG20160505T140502 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:35
channel c2: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0ur4r3gf_1_1.bak tag=TAG20160505T140502 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:35
Finished backup at 05-MAY-16

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0vr4r3hi_1_1.bak tag=TAG20160505T140538 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-MAY-16

Starting Control File and SPFILE Autobackup at 05-MAY-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-07 comment=NONE
Finished Control File and SPFILE Autobackup at 05-MAY-16

database opened

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           21     05-MAY-16        
 Backup Piece       21     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak
Backup Set           22     05-MAY-16        
 Backup Piece       22     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak
Backup Set           24     05-MAY-16        
 Backup Piece       24     05-MAY-16          /u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05
Backup Set           27     05-MAY-16        
 Backup Piece       27     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0rr4r3c1_1_1.bak

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           21     05-MAY-16        
 Backup Piece       21     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak
Backup Set           22     05-MAY-16        
 Backup Piece       22     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak
Backup Set           24     05-MAY-16        
 Backup Piece       24     05-MAY-16          /u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05
Backup Set           27     05-MAY-16        
 Backup Piece       27     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0rr4r3c1_1_1.bak
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0mr4r37h_1_1.bak RECID=21 STAMP=911052018
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0lr4r37i_1_1.bak RECID=22 STAMP=911052018
deleted backup piece
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-05 RECID=24 STAMP=911052056
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0rr4r3c1_1_1.bak RECID=27 STAMP=911052162
Deleted 4 objects


specification does not match any backup in the repository

released channel: c1

released channel: c2

RMAN>




[oracle@rhel64 rman_cold]$ ls -lh
total 2.2G
-rw-r----- 1 oracle oinstall 9.4M May  5 14:05 control_PROD_20160505_0vr4r3hi_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:02 db_PROD_20160505_0pr4r3au_1_1.bak
-rw-r----- 1 oracle oinstall 424M May  5 14:02 db_PROD_20160505_0qr4r3at_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:05 db_PROD_20160505_0tr4r3gf_1_1.bak
-rw-r----- 1 oracle oinstall 425M May  5 14:05 db_PROD_20160505_0ur4r3gf_1_1.bak
[oracle@rhel64 rman_cold]$







【编写rman备份脚本】


[oracle@rhel64 ~]$ vi /u01/app/oracle/scripts/PROD_rman_fullbackup.sh

[oracle@rhel64 ~]$ cat /u01/app/oracle/scripts/PROD_rman_fullbackup.sh
#!/bin/sh

export PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/practice/scripts:/home/oracle/bin
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=PROD
export PATH=$PATH:$ORACLE_HOME/bin


rman target / nocatalog msglog=/u01/app/oracle/backup/rman_cold/PROD_fullrman_`/bin/date +%Y%m%d-%H%M%S`.log <<EOF

run{
shutdown immediate;
startup mount;
crosscheck backup;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup database format '/u01/app/oracle/backup/rman_cold/db_%d_%T_%U.bak';
backup current controlfile format '/u01/app/oracle/backup/rman_cold/control_%d_%T_%U.bak';
alter database open;
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
}
quit;
EOF
exit


[oracle@rhel64 ~]$



[oracle@rhel64 ~]$ chmod a+x /u01/app/oracle/scripts/PROD_rman_fullbackup.sh
[oracle@rhel64 ~]$ ls -l /u01/app/oracle/scripts/
total 4
-rwxr-xr-x 1 oracle oinstall 903 May  5 14:16 PROD_rman_fullbackup.sh



手动执行脚本测试
[oracle@rhel64 ~]$ /u01/app/oracle/scripts/PROD_rman_fullbackup.sh
RMAN> RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> RMAN> RMAN> [oracle@rhel64 ~]$
[oracle@rhel64 ~]$


查看生成备份文件及日志
[oracle@rhel64 rman_cold]$ ls -lh
total 2.2G
-rw-r----- 1 oracle oinstall 9.4M May  5 14:18 control_PROD_20160505_13r4r494_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:05 db_PROD_20160505_0tr4r3gf_1_1.bak
-rw-r----- 1 oracle oinstall 425M May  5 14:05 db_PROD_20160505_0ur4r3gf_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 14:18 db_PROD_20160505_11r4r482_1_1.bak
-rw-r----- 1 oracle oinstall 426M May  5 14:17 db_PROD_20160505_12r4r481_1_1.bak
-rw-r--r-- 1 oracle oinstall 6.4K May  5 14:18 PROD_fullrman_20160505-141720.log
[oracle@rhel64 rman_cold]$
 

查看备份日志
[oracle@rhel64 rman_cold]$ more PROD_fullrman_20160505-141720.log

Recovery Manager: Release 11.2.0.3.0 - Production on Thu May 5 14:17:20 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=321736713)
using target database control file instead of recovery catalog

RMAN>
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15>
database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     521936896 bytes

Fixed Size                     2229944 bytes
Variable Size                373295432 bytes
Database Buffers             142606336 bytes
Redo Buffers                   3805184 bytes

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak RECID=25 STAMP=911052125
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak RECID=26 STAMP=911052126
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06 RECID=28 STAMP=911052163
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0ur4r3gf_1_1.bak RECID=29 STAMP=911052303
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0tr4r3gf_1_1.bak RECID=30 STAMP=911052303
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0vr4r3hi_1_1.bak RECID=31 STAMP=911052339
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-07 RECID=32 STAMP=911052340
Crosschecked 7 objects


released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=18 device type=DISK

allocated channel: c2
channel c2: SID=19 device type=DISK

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
channel c1: starting piece 1 at 05-MAY-16
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
channel c2: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_11r4r482_1_1.bak tag=TAG20160505T141737 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:35
channel c2: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_12r4r481_1_1.bak tag=TAG20160505T141737 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:35
Finished backup at 05-MAY-16

Starting backup at 05-MAY-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 05-MAY-16
channel c1: finished piece 1 at 05-MAY-16
piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_13r4r494_1_1.bak tag=TAG20160505T141812 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-MAY-16

Starting Control File and SPFILE Autobackup at 05-MAY-16
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-08 comment=NONE
Finished Control File and SPFILE Autobackup at 05-MAY-16

database opened

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           25     05-MAY-16        
 Backup Piece       25     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak
Backup Set           26     05-MAY-16        
 Backup Piece       26     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak
Backup Set           28     05-MAY-16        
 Backup Piece       28     05-MAY-16          /u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06
Backup Set           31     05-MAY-16        
 Backup Piece       31     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0vr4r3hi_1_1.bak

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           25     05-MAY-16        
 Backup Piece       25     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak
Backup Set           26     05-MAY-16        
 Backup Piece       26     05-MAY-16          /u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak
Backup Set           28     05-MAY-16        
 Backup Piece       28     05-MAY-16          /u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06
Backup Set           31     05-MAY-16        
 Backup Piece       31     05-MAY-16          /u01/app/oracle/backup/rman_cold/control_PROD_20160505_0vr4r3hi_1_1.bak
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0qr4r3at_1_1.bak RECID=25 STAMP=911052125
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/db_PROD_20160505_0pr4r3au_1_1.bak RECID=26 STAMP=911052126
deleted backup piece
backup piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/c-321736713-20160505-06 RECID=28 STAMP=911052163
deleted backup piece
backup piece handle=/u01/app/oracle/backup/rman_cold/control_PROD_20160505_0vr4r3hi_1_1.bak RECID=31 STAMP=911052339
Deleted 4 objects


specification does not match any backup in the repository

released channel: c1

released channel: c2

RMAN>
RMAN>

Recovery Manager complete.
[oracle@rhel64 rman_cold]$




【手动执行计划任务命令测试】
/u01/app/oracle/scripts/PROD_rman_fullbackup.sh >> /u01/app/oracle/scripts/PROD_fullrman_`/bin/date +/%Y/%m/%d-/%H/%M/%S`.log 2>&1




编辑计划任务【测试环境 每10分钟备份一次】
[oracle@rhel64 ~]$ crontab -e
[oracle@rhel64 ~]$ crontab -l
0,10,20,30,40,50 * * * * /u01/app/oracle/scripts/PROD_rman_fullbackup.sh >> /u01/app/oracle/scripts/PROD_fullrman_`/bin/date +/%Y/%m/%d-/%H/%M/%S`.log 2>&1






约半小时左右 观察备份情况、rman备份日志
均正常,则修改计划任务
[oracle@rhel64 rman_cold]$ ls -lh
total 2.2G
-rw-r----- 1 oracle oinstall 9.7M May  5 17:10 control_PROD_20160505_2vr4recg_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 17:00 db_PROD_20160505_2pr4rdou_1_1.bak
-rw-r----- 1 oracle oinstall 429M May  5 17:00 db_PROD_20160505_2qr4rdou_1_1.bak
-rw-r----- 1 oracle oinstall 678M May  5 17:10 db_PROD_20160505_2tr4rebn_1_1.bak
-rw-r----- 1 oracle oinstall 429M May  5 17:10 db_PROD_20160505_2ur4rebn_1_1.bak
-rw-r--r-- 1 oracle oinstall 6.4K May  5 17:00 PROD_fullrman_20160505-170001.log
-rw-r--r-- 1 oracle oinstall 6.4K May  5 17:10 PROD_fullrman_20160505-171001.log
[oracle@rhel64 rman_cold]$



【生产环境,每天凌晨2点备份一次】
【编辑计划任务】
[oracle@rhel64 ~]$ crontab -e
[oracle@rhel64 ~]$ crontab -l
0 2 * * * /u01/app/oracle/scripts/PROD_rman_fullbackup.sh >> /u01/app/oracle/scripts/PROD_fullrman_`/bin/date +/%Y/%m/%d-/%H/%M/%S`.log 2>&1



日常巡检:查看rman备份情况
1.查看生成的备份日志 cat /u01/app/oracle/backup/rman_cold/xxx.log
2.查看生成的备份文件 ls -lh /u01/app/oracle/backup/rman_cold
3.监控文件系统空间使用  df -Th








吕星昊
2016.5.5

正文到此结束
Loading...