The purpose of any backup and recovery strategy is data safety, as well as the ability to restore (and quickly enough) if needed. The same goes for Oracle databases. Creating a backup and recovery system is necessary to protect the contents of Oracle databases.
There are a number of tasks that backup administration personnel are responsible for, including:
- Backup schedule creation;
- Backup troubleshooting;
- Data loss recovery;
- Different scenario testing;
- Backup and recovery environment monitoring, and so on.
If we’re talking about creating a backup of an Oracle database using Bacula’s, the entire process can be summed up in three major steps:
- Initial setup and file preparation
- Bacula job configuration and initialization
- Snapshot destruction
Initial setup and file preparation
Everything begins with running your Oracle database in Archive Log mode, it can be done in two steps:
- Actually running the database in ARCHIVELOG mode;
- Using a specific parameter to point to the location that would be storing Archival Logs in the first place, for example:
LOG_ARCHIVE_DEST_1 = 'LOCATION=/disk1/var/backup/oracle/arch'
The Archive Log mode in this case is needed to have all of the archived log files, these files are needed for the complete and successful restoration of backups we are about to create.
Next we’ll have to create a script that can put our Oracle database into the backup mode. It’ll be called start-backup-mode.sh and we are placing it in the following direction – /opt/oraappl/scripts. The contents of this script file are as follows:
#!/bin/bash
sqlplus /nolog <<EOF
conn sys/managger as sysdba
alter database begin backup;
exit
EOF
While it is possible to perform Oracle backup and recovery process without snapshots, it is recommended to use snapshots in order to decrease backup mode operation time. To use the snapshot technology in the backup process with the Oracle backup solution, we need the following lines in the previous file (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/
To order the script to exit the Oracle database backup mode after the backup process is done, we’ll be using the following command as the last part of the start-backup-mode.sh file:
sqlplus /nolog <<EOF
conn sys/managger as sysdba
alter database end backup;
exit
EOF
The final version of our backup script example should look like this:
#!/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
Bacula job configuration and initialization
To be able to run scripts properly, Bacula as an Oracle backup solution needs the Oracle user’s permissions, and to have this we’ll be using the following lines in /etc/sudoers at Linux Server running our Oracle database:
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
There’s a number of commands that’ll be used to configure the Bacula backup jobs in this case:
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"
}
The example above specifies a number of things, including:
- A command to backup all of the snapshot volumes once a day (mnt/snap/var/oradata and /mnt/snap/opt/oraappl);
- A command to backup all of the archive logs 6 times a day (4 hour interval, the folder in question is /var/backup/oracle/arch/);
- A command RunBeforeJob that activates Oracle database backup mode;
- A command RunAfterJob that deactivates Oracle database backup mode.
Snapshot destruction
After the backup process is done, the original snapshot files are no longer needed, so it’s safe to remove them. You may have noticed in the previous step that there’s an additional file in the configuration called stop-backup-mode.sh. This is the file that completes the backup process and deletes the snapshot files automatically, according to the Oracle backup tool settings. This script should be created at /opt/oraappl/scripts/stop-backup-mode.sh with the following contents:
#!/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
As previously stated, there are a variety of ways of making sure that your Oracle databases are secure by backing them up, including the use of third-party Oracle backup tools such as Bacula. Find out more about Bacula’s free Oracle backup software here.
If you’re also interested in Hyper V Backup, check out Bacula’s solution.