Oracle backup with RMAN
Deploying an Oracle database is one thing, but doing a good recovery backup plan is another matter. Good for us, Oracle comes with its own tool for doing backups called “RMAN”.
Sure, one can do backup with the Enterprise Manager, but with it you will need to shut down the database in order to do a backup. Not exactly, what is needed with a production database that is online 24/7 and can’t afford a shutdown. In order to do a “online backup” one needs to run a script for RMAN.
RMAN uses the same login settings as your SQLPLUS login and thus it should be rather easy to do so. In our case we have also configured a backup catalog within Oracle with its own tablespace. Once done a backup script can be run each night with crontab.
Here is how to setup the backup catalog:
SQL> create user rman identified by rman;
SQL> alter user rman default tablespace tools temporary tablespace temp;
SQL> alter user rman quota unlimited on tools;
SQL> grant connect, resource, recovery_catalog_owner to rman;
in case you don’t have a tablespace called “tools” you need to create it with:
create tablespace tools
next 32m maxsize 2048m
extent management local;
Now you can log in to RMAN create the catalog schema with:
rman catalog rman/rman
RMAN> create catalog tablespace tools;
Then register the database with;
rman catalog rman/rman target sys/password@ORCL
RMAN> register database;
Make sure you connect to the database that you need to backup!
I then created a script that will keep my backup for 2 days. I also have a script that will compress the backup files and move them to another server. Here is my backup script:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
ALLOCATE CHANNEL RMAN_BACK_CH01 TYPE DISK;
BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FORMAT
'/opt/oracle/backup/archivelogs_%d_%u_%s_%T' DELETE INPUT;
BACKUP AS COMPRESSED BACKUPSET CURRENT CONTROLFILE FORMAT
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED BACKUP;
RELEASE CHANNEL RMAN_BACK_CH01;
This will backup your control file, archive log and database. It will also compress the backup and will remove the old files.
In my case, I saved the above script as RMA_backup.txt and have a RMAN_script.sh with the following inside:
rman target sys/password@ORCL @/opt/rman_backup.txt;
I have seen that sometimes we got errors running the above script with:
RMAN-06207: WARNING: 5 objects could not be deleted for DISK channel(s) due
RMAN-06208: to mismatched status. Use CROSSCHECK command to fix status
RMAN-06210: List of Mismatched objects
With RMAN you can check your backup with the following commands:
CROSSCHECK backup of database;
CROSSCHECK backup of controlfile;
CROSSCHECK archivelog all;
If all goes well, you should not get any errors running these commands. Still we had the above errors, even thought I issued the command to delete obsolte control files with;
DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 2 DAYS;
The key to success was when I used the “FORCE” command as;
DELETE FORCE NOPROMPT OBSOLETE RECOVERY WINDOW OF 2 DAYS;
Hope this helps anybody. There is a good reference for backups over at the Oracle FAQ.