If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Script required for RMAN backups

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-31-11, 08:27
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
Script required for RMAN backups

Hi All,

I'm a junior dba working with oracle 11.2.0.1 on Linux 5 platform

My question is as follows:-

I have my backup policy running via RMAN like this :-

Monthly backup:

BACKUP DATABASE PLUS ARCHIVELOG LEVEL 0;

Weekly backup:
BACKUP INCREMENTAL LEVEL 1
TABLESPACE SYSTEM, DM_UKROWMASTER_TEST_DOCBASE, DM_UKROWMASTER_TEST_INDEX ;

Daily backup:
BACKUP INCREMENTAL LEVEL = 1 CUMULATIVE
TABLESPACE SYSTEM, DM_UKROWMASTER_TEST_DOCBASE, DM_UKROWMASTER_TEST_INDEX, USERS;

What I would like is to schedule one script via cron, to take the monthly backup on the 1st of each month and run at 04:00 in the morning.
The weekly backup to run every Sunday morning at 04:00am and the Daily backup to run at 04:00 every morning.

I wanted the script basically to check for the current date and execute what ever section is appropriate for that date

Many thanks for your assistance
Reply With Quote
  #2 (permalink)  
Old 05-31-11, 08:44
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Code:
day_of_month=`date +"%e"`      # 1 thru 31
day_of_week=`date +"%u"`       #monday=1, Sunday=7
if [ $day_of_month -eq 1 ]
then
   do_monthly
   exit
fi
if [ $day_of_week -eq 7 ]
then
  do_weekly
  exit
fi
do_daily
Reply With Quote
  #3 (permalink)  
Old 06-01-11, 04:52
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
Can you check and let me know if this is OK

put your rman command into a script the script using he RUN { ...} Rman syntax
example

/u01/app/oracle/admin/DCTMPROD/scripts/rman_DCTMPROD_backup.sh

[oracle@UKEDXDTMDBS01A scripts]$ pwd
/u01/app/oracle/admin/DCTMPROD/scripts

[oracle@UKEDXDTMDBS01A scripts]$ more rman_DCTMPROD_backup.sh

RUN{
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_DCTMPROD1.f'; # default
}

[oracle@UKEDXDTMDBS01A scripts]$

The script can then for example be run with :

su - oracle -c "rman target / catalog rman/DCTM-rman@DCTMPROD/u01/app/oracle/admin/DCTMPROD/scripts/rman_DCTMPROD_backup.sh"

Then there are 3 seperate shell scripts for the different backups

[oracle@UKEDXDTMDBS01A scripts]$ ls -ltr *backup*
-rw-r--r-- 1 oracle oinstall 133 Jun 1 09:37 rman_DCTMPROD_monthlybackup.sh
-rw-r--r-- 1 oracle oinstall 196 Jun 1 09:41 rman_DCTMPROD_weeklybackup.sh
-rw-r--r-- 1 oracle oinstall 214 Jun 1 09:44 rman_DCTMPROD_dailybackup.sh
[oracle@UKEDXDTMDBS01A scripts]$

a) rman_DCTMPROD_monthlybackup.sh
b) rman_DCTMPROD_weeklybackup.sh
c) rman_DCTMPROD_dailybackup.sh

scripts:

[oracle@UKEDXDTMDBS01A scripts]$ more rman_DCTMPROD_monthlybackup.sh
export ORACLE_SID=DCTMPROD1
su - oracle
rman target / catalog rman/DCTM-rman@DCTMPROD1
BACKUP DATABASE PLUS ARCHIVELOG LEVEL 0;
exit

[oracle@UKEDXDTMDBS01A scripts]$ more rman_DCTMPROD_weeklybackup.sh
export ORACLE_SID=DCTMPROD1
su - oracle
rman target / catalog rman/DCTM-rman@DCTMPROD1
BACKUP INCREMENTAL LEVEL 1
TABLESPACE SYSTEM, DM_UKROWMASTER_TEST_DOCBASE, DM_UKROWMASTER_TEST_INDEX ;
exit

[oracle@UKEDXDTMDBS01A scripts]$ more rman_DCTMPROD_dailybackup.sh
export ORACLE_SID=DCTMPROD1
su - oracle
rman target / catalog rman/DCTM-rman@DCTMPROD1
BACKUP INCREMENTAL LEVEL = 1 CUMULATIVE
TABLESPACE SYSTEM, DM_UKROWMASTER_TEST_DOCBASE, DM_UKROWMASTER_TEST_INDEX, USERS;
exit

Your feedback will be much appreciated

Many thanks
Reply With Quote
  #4 (permalink)  
Old 06-02-11, 06:37
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
I managed to get my backup script to work

I took it a step further by trying to make the backups go into daily folder and adding a log file - as seen below

[oracle@ukedxdtmtdbs01a scripts]$ more backup.sh
#!/bin/ksh
export ORACLE_SID=DCTMTEST1
Today="`date +%d%m%Y`" # month number, day of month, year
mkdir DCTMTEST_rman_backups_$Today
rman target / catalog rman/DCTM-rman@DCTMTEST log DCTMTEST_rman_backups_$Today<< EOF
RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backups/DCTMTEST_rman_backups_$Today/%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;
EOF

Just a few points:

a) I would like to mail the log file as an attachment to an email address such as name@company.com
b) What is the syntax and where do I place it within this file

I thought it was mail -x or similar
Reply With Quote
  #5 (permalink)  
Old 06-02-11, 09:26
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Code:
mail -s "Backup Log" name@company.com <log.file
This will send the log file as the text of the email. If you want to send it as an attachment, then use "mutt"
Code:
mutt -a log.file -s "Subject" name@company.com <letter.txt
Reply With Quote
  #6 (permalink)  
Old 06-06-11, 03:33
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
OK I managed to get those scripts working, however when I schedule via cron I get permission error -
although the cron is from oracle and the script has oracle ownership. It was scheduled to run at 4am
this morning and this is the error I get from var/log/messages.1 and cron.1

[oracle@ukedxdtmtdbs01a log]$ pwd
/var/log
[oracle@ukedxdtmtdbs01a log]$ more messages.1
messages.1: Permission denied
[oracle@ukedxdtmtdbs01a log]$ more cron.1
cron.1: Permission denied

[oracle@ukedxdtmtdbs01a log]$ crontab -l
#! Automatic scheduling of RMAN Backups -- June 2011
00 4 1 * * /u01/app/oracle/product/11.2.0/db_1/sysman/admin/scripts/backup_monthly.sh
00 4 * * 0 /u01/app/oracle/product/11.2.0/db_1/sysman/admin/scripts/backup_weekly.sh
00 4 * * 1-5 /u01/app/oracle/product/11.2.0/db_1/sysman/admin/scripts/backup_daily.sh

this is the actual script - which when run interactively from the oracle account works perfectly

[oracle@ukedxdtmtdbs01a scripts]$ more backup_weekly.sh
#!/bin/ksh
#! Weekly Backup for Test Environment - Perform backup compressed
export ORACLE_SID=DCTMTEST1
mkdir /u01/backups/DCTMTEST_rman_backups_weekly
rman target / catalog rman/DCTM-rman@DCTMTEST log=/u01/backups/DCTMTEST_rman_backups_weekly/DCTMTEST_rman_backups_weekly.log<< EOF
RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backups/DCTMTEST_rman_backups_weekly/%d_DB_%u_%s_%p';
BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG Tag = 'Weekly Test Backup';
RELEASE CHANNEL ch1;
}
EOF
# Mail log file to the Oracle DBA
mail -s 'RMAN Weekly Backup Log for Test' name@company.com < /u01/backups/DCTMTEST_rman_backups_weekly/DCTMTEST_rman_backups_weekly.log

Is there something I need to include in the script, prior to executing the RMAN commands to get this script to run successfully?
Reply With Quote
  #7 (permalink)  
Old 06-06-11, 10:51
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
Backup still fails via cron

Hi,

just scheduled another backup

The user which runs the backup is oracle

the protection on /u01/backups is as follows:-

ls -ltr /u01

drwxrwxrwx 5 oracle oinstall 4096 Jun 6 15:40 backups

As you can see it creates the directory

[oracle@ukedxdtmtdbs01a u01]$ ls -ltr backups
total 12

drwxr-xr-x 2 oracle oinstall 4096 Jun 6 15:40 DCTMTEST_rman_backups_06062011

It still produces the same error

[oracle@ukedxdtmtdbs01a tmp]$ more backup_daily.log
/u01/app/oracle/product/11.2.0/db_1/sysman/admin/scripts/backup_daily.sh[6]: rman: not found [No such file or directory]
/u01/app/oracle/product/11.2.0/db_1/sysman/admin/scripts/backup_daily.sh: line 17: /u01/backups/DCTMTEST_rman_backups_0606
2011/DCTMTEST_rman_backups_06062011.log: cannot open [No such file or directory]

I think the problem could be that it does not recognise the rman command via cron, where as when you run the procedure from the command line it has no issues.

Thanks again,
Reply With Quote
  #8 (permalink)  
Old 06-06-11, 12:45
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
The PATH statement in cron is typically quite different than a login session.
Add "env > /tmp/cron.env" to the script to display the environment, and then adjust the script accordingly.
Reply With Quote
  #9 (permalink)  
Old 06-06-11, 15:41
tspoon tspoon is offline
Registered User
 
Join Date: Jun 2005
Posts: 23
rman backups via cron now works

Hi,

thanks for the feedback, I changed the script accordingly and it now works

Thanks again
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On