This Howto describe how run a backup Oracle Databases with Bacula without downtime.
Contributed by Victor Hugo dos Santos <contacto.vhs at gmail.com>
In production environment downtimes of DB isn't allowed, for around this problem, we will need:
tablespace individually).
First step is configure your Oracle DB for work in Archive Log modes, you can read this documents:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/archredo.htm#i1006184
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/archredo004.htm
In my case, I send archive logs to folder /var/backup/oracle/arch
Now, we need create a script called start-backup-mode.sh in /opt/oraappl/scripts with this content:
#!/bin/bash sqlplus /nolog <<EOF conn sys/managger as sysdba alter database begin backup; exit EOF
This lines putting database in backup mode.
This step is optional because in that moment is possible running a backup DB files directly from original folder (/var/oradata) with bacula, but personally I prefer create a snapshot of data to reduce backup mode operation time (the bad news is that if you have much access/changes in snapshot source, the IO can be reduced performance on server).
If you prefer (a same that me) create a snapshot, so you need aggregate this lines to end start-backup-mode.sh
/usr/sbin/lvcreate -L 20G -s -n oradata-snap oradata /usr/sbin/lvcreate -L 20G -s -n oraappl-snap oraappl mount /dev/VG_DATA/oradata-snap /mnt/snapshots/var/oradata/ mount /dev/VG_DATA/oraappl-snap /mnt/snapshots/opt/oraappl/
that lines create and mount Snapshots volumes. Obs.: In this example, your Linux Server need have a 40GB free in VolumeGroup to create a SnapShots
Now, we have a Snapshot of files and we can unset Oracle DB backup mode, add this lines to end start-backup-mode.sh:
sqlplus /nolog <<EOF conn sys/managger as sysdba alter database end backup; exit EOF
the start-backup-mode.sh final script is:
#!/bin/bash # Put DB in backup mode sqlplus /nolog <<EOF conn sys/managger as sysdba alter database begin backup; exit EOF # Create and mount Snapshots /usr/sbin/lvcreate -L 20G -s -n oradata-snap oradata /usr/sbin/lvcreate -L 20G -s -n oraappl-snap oraappl mount /dev/VG_DATA/oradata-snap /mnt/snapshots/var/oradata/ mount /dev/VG_DATA/oraappl-snap /mnt/snapshots/opt/oraappl/ # Unset DB backup mode sqlplus /nolog <<EOF conn sys/managger as sysdba alter database end backup; exit EOF exit 0
If all is OK.. we having:
now is need configure Bacula's Jobs.
Bacula need run scripts start-backup-mode.sh and stop-backup-mode.sh as oracle's user, for this we need aggregate this lines in /etc/sudoers in Linux Server that is running a BD Oracle instance:
Cmnd_Alias BACKUP_ORACLE = /bin/su - oracle -c /opt/oraappl/scripts/start-backup-mode.sh, /bin/su - oracle -c /opt/oraappl/scripts/start-backup-mode.sh bacula LOCAL = NOPASSWD: BACKUP_ORACLE
Too is need configure the Job in Bacula Director, add this lines for your configuration:
FileSet { Name = "Linux-Oracle-SNAPs" Include { Options { signature = SHA1; compression=GZIP6; strippath=2 } File = /mnt/snap/var/oradata File = /mnt/snap/opt/oraappl File = /usr/local/bin/ File = /etc/oratab } } FileSet { Name = "Linux-Oracle-ARCs" Include { Options { signature = SHA1; compression=GZIP6 } File = /var/backup/oracle/arch/ } } Schedule { Name = "Oradata-Cycle" Run = Full sun at 02:30 Run = Incremental mon-sat at 02:30 } Schedule { Name = "Oracle-AchiveLogs-Cycle" Run = Full sun at 04:30 Run = Incremental mon-sat at 04:00 Run = Incremental mon-sat at 08:00 Run = Incremental mon-sat at 12:00 Run = Incremental mon-sat at 16:00 Run = Incremental mon-sat at 20:00 Run = Incremental mon-sat at 24:00 } Job { Name = "oracle-hotbackup" Client = oracleserver-fd JobDefs = "DefaultJob" Schedule = "Oradata-Cycle" RunBeforeJob = "sudo /bin/su - oracle -c /opt/oraappl/scripts/start-backup-mode.sh" RunAfterJob = "sudo /bin/su - oracle -c /opt/oraappl/scripts/stop-backup-mode.sh" FileSet = "Linux-Oracle-SNAPs" Write Bootstrap = "/var/lib/bacula/oracle-hotbackup.bsr" } Job { Name = "oracle-archivelog" Client = oracleserver-fd JobDefs = "DefaultJob" Schedule = "Oracle-AchiveLogs-Cycle" FileSet = "Linux-Oracle-ARCLOGS" Write Bootstrap = "/var/lib/bacula/oracle-archivelog.bsr" }
Well, in this example we have a two jobs:
In the first jobs (oracle-hotbackup) we are using the directives:
Well, after of finish the Backup Job, we have a backup of all data and application of Oracle in we storages and the Snapshot isn't more need, so we can remove it. But, the true is that Bacula automatic remove it because we configured RunAfterJob directive in Director and only needing create a /opt/oraappl/scripts/stop-backup-mode.sh script file with this content:
#!/bin/sh # Umount and Destroy Snapshots umount /mnt/snapshots/var/oradata/ umount /mnt/snapshots/opt/oraappl/ lvremove -f /dev/VG_DATA/oradata-snap lvremove -f /dev/VG_DATA/oraappl-snap exit 0
http://becomeappsdba.blogspot.com/2006/09/backup-recovery-in-oracle-apps.html
http://wiki.bacula.org/doku.php?id=application_specific_backups:oracle_rdbms
I would like to thank to following people, not in any particular order: