Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2005
    Posts
    29

    Unanswered: 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

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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

  3. #3
    Join Date
    Jun 2005
    Posts
    29

    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

  4. #4
    Join Date
    Jun 2005
    Posts
    29
    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

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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

  6. #6
    Join Date
    Jun 2005
    Posts
    29
    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?

  7. #7
    Join Date
    Jun 2005
    Posts
    29

    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,

  8. #8
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    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.

  9. #9
    Join Date
    Jun 2005
    Posts
    29

    rman backups via cron now works

    Hi,

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

    Thanks again

  10. #10
    Join Date
    Aug 2012
    Posts
    2
    Hii all

    i need rman cloning steps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •