We help IT Professionals succeed at work.

Oracle SQLPlus Shell Script for Begin, End backup

Hi,

I need some help for Oracle 11gR2 SQLPlus Shell Script. Appreciate if the expert can help.

script1.sh
- This script will run the flashcopy command
- Tested successful


UO1.sh (need help)
- Login to sqlplus
- Set database begin backup
- Call external script “script1.sh” for flashcopy. Wait for external script to complete
- Set database end backup

sqlplus -s /@dbname << EOF
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER DATABASE BEGIN BACKUP;
?? how to call script1.sh
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER DATABASE END BACKUP;
EOF


backupstat.sh (to check if database in backup mode, end the backup mode – good to have, we are scheduling the script to run @ 4am)
- Login to sqlplus
- Checking database V$BACKUP
- If backup mode, then end backup mode
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
replace "?? how to call script1.sh"

with:

host .\script1.sh

Author

Commented:
Thank you.

anyone can comment if my sqlplus backup command making sense?
Commented:
It should be

host ./script1.sh
Commented:
== > you could also try something like this....

script_name="script1.sh"
          rc=$?

          if [ $rc -ne 0 ]
          then
               host "./$script_name"
          fi
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:
>if my sqlplus backup command making sense?

I understand what it is doing.  Not sure I would place an entire database in backup mode at once.  It would depend on the activity at the time.  backup mode can generate A LOT of redo on active databases.

The piece you might be missing is backing up the archived redo logs generated while in backup mode but that might be part of another backup script.
johnsoneSenior Oracle DBA
CERTIFIED EXPERT

Commented:
How are you determining which files to back up?  Is it a fixed list?  If it is, that is bad practice as if a file is added to the database then you will miss it unless a script is updated.  If you go by mount points, then same issue, once a mount point is added you will miss everything.

Running backupstat.sh at a given time is bad as well.  It is a good script to have, but if it runs at a fixed time and your backup isn't complete yet, then your backup is invalid.

I will re-iterate the need to backup archive logs as well.  You need to switch archive logs, and back them up once your database backup is complete.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.