How to Backup Oracle oratab, .bash_profile, and Environment Variables
Before performing system-level or Oracle patching activities, it’s a best practice to back up not only your Oracle binaries and inventory but also critical configuration files such as oratab, .bash_profile, and the environment variables. These files play a vital role in defining Oracle instance behavior and user environment settings.
📑 Why These Backups Matter
- oratab: Lists installed Oracle instances and is used by utilities like dbstart and dbshut.
- .bash_profile: Contains user-specific environment settings, especially for
oracle
OS user. - Environment variables: Define how Oracle tools behave (e.g., ORACLE_HOME, ORACLE_SID,
PATH
).
📂 Backup Location Recommendation
Create a dedicated backup directory to store these configuration files:
mkdir -p /u02/oracle/backup/config
🔧 Step-by-Step Backup Guide
✅ 1. Backup oratab File
This file is typically located at /etc/oratab
.
📌 Command:
cp -p /etc/oratab /u02/oracle/backup/config/oratab.bak
📤 Example Output:
[oracle@dbhost ~]$ cp -p /etc/oratab /u02/oracle/backup/config/oratab.bak
[oracle@dbhost ~]$ ls -l /u02/oracle/backup/config/oratab.bak
-rw-r--r-- 1 root root 215 Mar 27 10:45 /u02/oracle/backup/config/oratab.bak
✅ 2. Backup .bash_profile for Oracle User
Make sure you’re logged in as oracle
or switch to the Oracle user.
📌 Command:
cp -p ~/.bash_profile /u02/oracle/backup/config/bash_profile.bak
📤 Example:
[oracle@dbhost ~]$ cp -p ~/.bash_profile /u02/oracle/backup/config/bash_profile.bak
💡 Note: You can also backup .bashrc if it’s used for environment settings.
✅ 3. Backup Current Environment Variables
You may want to record the current shell environment for reference, especially variables like ORACLE_HOME, ORACLE_SID, and PATH.
📌 Command:
env > /u02/oracle/backup/config/env_backup_$(date +%Y%m%d).txt
📤 Example:
[oracle@dbhost ~]$ env > /u02/oracle/backup/config/env_backup_20250527.txt
🔎 This will create a plain text file with all environment variables set for the current session.
📥 Optional: Create a Tarball of All Config Backups
You can also compress everything into a single file for easy storage or migration.
📌 Command:
cd /u02/oracle/backup/config
tar -czvf oracle_env_config_backup_$(date +%Y%m%d).tar.gz ./*.bak ./*.txt
📤 Example:
oracle_env_config_backup_20250527.tar.gz
✅ Restore Steps (if needed)
- Restore oratab:
cp /u02/oracle/backup/config/oratab.bak /etc/oratab
- Restore .bash_profile:
cp /u02/oracle/backup/config/bash_profile.bak ~/.bash_profile
source ~/.bash_profile
- Review environment:
cat /u02/oracle/backup/config/env_backup_20250527.txt
📝 Final Notes
- Always take these backups before any patching or upgrade.
- Automate this process in your patching pre-checklist or script.
- Store backups in a secure, versioned location.