Apps DBA Workshop

Tuesday, 27 March 2012

rman backup script in crontab

rman backup script fails to run in crontab where as it will succeed if executed manually.

Here i am going to use a simple script just to demonstrate the successful run of rman backup script in crontab.

If cronjob failed then it will generate the log information in "/var/mail/ora11g" (here ora11g is username)

If the script is not written properly then it will give error messages as below:



/home/ora11g/db_scripts/rman_bkp1.sh[6]: RUN: not found [No such file or directory]
/home/ora11g/db_scripts/rman_bkp1.sh[7]: ALLOCATE: not found [No such file or directory]
/home/ora11g/db_scripts/rman_bkp1.sh[8]: DISK: not found [No such file or directory]
/home/ora11g/db_scripts/rman_bkp1.sh[9]: BACKUP: not found [No such file or directory]
/home/ora11g/db_scripts/rman_bkp1.sh[10]: RELEASE: not found [No such file or directory]
/home/ora11g/db_scripts/rman_bkp1.sh: line 10: syntax error at line 11: `}' unexpected



sample script which will run successful in crontab:





There is no backup for this database in repository:



[ora11g@oelrac1 db_scripts]$ rman

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 27 13:25:21 2012

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

RMAN> connect target

connected to target database: TESTRAC (DBID=155295882)

RMAN> list backup;

using target database control file instead of recovery catalog
specification does not match any backup in the repository

RMAN>




I have schedule cronjob to execute at 13:28 hours. This will generate logfile "/home/ora11g/db_scripts/logs/cron1" for this session:



[ora11g@oelrac1 db_scripts]$ crontab -l
28 13 * * * /home/ora11g/db_scripts/rman_bkp1.sh ORA11G > /home/ora11g/db_scripts/logs/cron1
[ora11g@oelrac1 db_scripts]$ date
Tue Mar 27 13:26:49 AST 2012
[ora11g@oelrac1 db_scripts]$






[ora11g@oelrac1 logs]$ ls -lrt
total 8
drwxr-xr-x 2 ora11g dba 4096 Mar 27 12:03 cron
-rw-r--r-- 1 ora11g dba 1778 Mar 27 13:29 cron1
[ora11g@oelrac1 logs]$ pwd
/home/ora11g/db_scripts/logs
[ora11g@oelrac1 logs]$




content of rman backup cronjob logfile:



[ora11g@oelrac1 logs]$ more cron1

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 27 13:28:02 2012

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

connected to target database: TESTRAC (DBID=155295882)

RMAN> 2> 3> 4> 5> 6>
using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: SID=33 instance=testrac1 device type=DISK

Starting backup at 27-MAR-12
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=+RACDATA/testrac/datafile/system.256.777637199
input datafile file number=00002 name=+RACDATA/testrac/datafile/sysaux.257.777637203
input datafile file number=00003 name=+RACDATA/testrac/datafile/undotbs1.258.777637203
input datafile file number=00005 name=+RACDATA/testrac/datafile/example.264.777637363
input datafile file number=00006 name=+RACDATA/testrac/datafile/undotbs2.265.777637637
input datafile file number=00004 name=+RACDATA/testrac/datafile/users.259.777637203
channel ch1: starting piece 1 at 27-MAR-12
channel ch1: finished piece 1 at 27-MAR-12
piece handle=/u01/11g_db/rman_db_backups/TESTRAC_DB_0dn6u4b6_13_1 tag=TAG20120327T132806 comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:08
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 27-MAR-12
channel ch1: finished piece 1 at 27-MAR-12
piece handle=/u01/11g_db/rman_db_backups/TESTRAC_DB_0en6u4dc_14_1 tag=TAG20120327T132806 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:03
Finished backup at 27-MAR-12

released channel: ch1

RMAN>

Recovery Manager complete.




After successful backup information in repository:




[ora11g@oelrac1 db_scripts]$ rman

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 27 13:30:43 2012

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

RMAN> connect target

connected to target database: TESTRAC (DBID=155295882)

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
13 Full 1.06G DISK 00:01:07 27-MAR-12
BP Key: 13 Status: AVAILABLE Compressed: NO Tag: TAG20120327T132806
Piece Name: /u01/11g_db/rman_db_backups/TESTRAC_DB_0dn6u4b6_13_1
List of Datafiles in backup set 13
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/system.256.777637199
2 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/sysaux.257.777637203
3 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/undotbs1.258.777637203
4 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/users.259.777637203
5 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/example.264.777637363
6 Full 1061149 27-MAR-12 +RACDATA/testrac/datafile/undotbs2.265.777637637

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14 Full 17.70M DISK 00:00:08 27-MAR-12
BP Key: 14 Status: AVAILABLE Compressed: NO Tag: TAG20120327T132806
Piece Name: /u01/11g_db/rman_db_backups/TESTRAC_DB_0en6u4dc_14_1
SPFILE Included: Modification time: 27-MAR-12
SPFILE db_unique_name: TESTRAC
Control File Included: Ckp SCN: 1061326 Ckp time: 27-MAR-12

RMAN>




Hope this helps :)

thanks for reading.

regards,
Syed Zaheer

Labels: , , ,

1 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home