Automating Oracle 19c Backups with Crontab: Solving RMAN Errors
Automating Oracle 19c Backups with Crontab: Solving RMAN Errors
Automating Oracle backups is a common task for database administrators. Using crontab to schedule backups simplifies this process. However, there can be challenges along the way. One such challenge is encountering errors related to the RMAN (Recovery Manager) command execution. In this article, we’ll address a specific error related to the RMAN message file and provide a solution to fix it.

The Problem
After setting up a crontab job to execute an RMAN backup script, you might encounter an error message similar to the following:
Message file RMAN<lang>.msb not found
Verify that ORACLE_HOME is set properly
/home/kemal/scripts/backup_script.rman: line 6: $'\r': command not found
The error indicates that the RMAN message file is not found and suggests verifying the ORACLE_HOME environment variable. Additionally, the $'\r' error suggests there might be carriage return characters in the script, which can cause issues when executing the commands.
The Solution
To resolve these issues, follow the steps below:
1. Update the RMAN Script
Edit the RMAN script /home/kemal/scripts/backup_script.rman to set the ORACLE_HOME and other environment variables correctly and remove any carriage return characters.
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/19/db
export PATH=$ORACLE_HOME/bin:$PATH
export LANG=en_US.UTF-8
export ORACLE_SID=ccbs
# Remove carriage return characters
sed -i 's/\r$//' /home/kemal/scripts/backup_script.rman
# Execute RMAN backup
/u01/app/oracle/product/19/db/bin/rman target sys/test123 <<< "backup database format '/backup/crontab/%d_%t_%s.rman';"
2. Remove Carriage Return Characters
Use the sed command to remove carriage return characters from the script. This command replaces any carriage return character (\r) at the end of lines with nothing, effectively removing them.
sed -i 's/\r$//' /home/kemal/scripts/backup_script.rman
3. Test the Crontab Job
After updating the script, test the crontab job to ensure it executes without any errors.
52 09 * * * /home/kemal/scripts/backup_script.rman > /home/kemal/scripts/logfile
Conclusion
Automating Oracle 19c backups using crontab can be efficient and time-saving. However, it’s essential to address and resolve any errors that may arise during the process. By updating the RMAN script to set environment variables correctly and removing carriage return characters, you can ensure a smooth and error-free backup process.
Remember to always test your crontab jobs after making changes to ensure they work as expected. Happy automating!
← PostgreSQL Blog