Skip to main content

Daily backup check: full alias instructions

SCRIPT INSTALLATION

1. Copy the script to the server:

# Create the directory if it does not exist
mkdir -p /home/oracle/dba/backup_check

# Copy the script
scp check_daily_backup.sh oracle@dbserver01:/home/oracle/dba/backup_check/

# Or via FTP/SFTP

2. Grant execute permission:

chmod +x /home/oracle/dba/backup_check/check_daily_backup.sh

3. Adjust the log paths in the script:

vi /home/oracle/dba/backup_check/check_daily_backup.sh

# Edit the LOG_FILES=( ... ) section with the correct paths to your logs

CONFIGURE THE ALIASES

Option 1: For the oracle user only (.bashrc)

# Edit .bashrc
vi ~/.bashrc

# Add at the end of the file:
alias bkp="/home/oracle/dba/backup_check/check_daily_backup.sh"
alias bkp_1day="/home/oracle/dba/backup_check/check_daily_backup.sh yesterday"
alias bkp_yesterday="/home/oracle/dba/backup_check/check_daily_backup.sh yesterday"
alias bkp_2days="/home/oracle/dba/backup_check/check_daily_backup.sh '2 days ago'"

# Reload the configuration
source ~/.bashrc

Option 2: For all users (global .bash_profile)

# Edit the global profile
sudo vi /etc/profile.d/backup_aliases.sh

# Add:
#!/bin/bash
alias bkp="/home/oracle/dba/backup_check/check_daily_backup.sh"
alias bkp_1day="/home/oracle/dba/backup_check/check_daily_backup.sh yesterday"
alias bkp_yesterday="/home/oracle/dba/backup_check/check_daily_backup.sh yesterday"

# Grant permission
sudo chmod +x /etc/profile.d/backup_aliases.sh

# Log in again or run:
source /etc/profile.d/backup_aliases.sh

USING THE ALIASES

Available commands:

# Check TODAY's backups
bkp

# Check YESTERDAY's backups
bkp_1day
# or
bkp_yesterday

# Check backups from 2 days ago
bkp_2days

# Check a specific date (flexible)
/home/oracle/dba/backup_check/check_daily_backup.sh "3 days ago"
/home/oracle/dba/backup_check/check_daily_backup.sh "2026-02-10"

SAMPLE OUTPUT

========================================
  BACKUP CHECK - TODAY
========================================
Date checked: 16/02/2026 (Sun Feb 16)

========================================
     BACKUP STATUS SUMMARY
========================================
Date: 16/02/2026
Total Databases: 30
Success: 28 | Error: 1 | Not Found: 1
========================================

### BACKUPS COMPLETED SUCCESSFULLY ###
PRODDB31        : ✓ SUCCESS  [01:23:45]
PRODDB21        : ✓ SUCCESS  [02:15:30]
PRODDB28        : ✓ SUCCESS  [03:45:12]
...

### BACKUPS COMPLETED WITH ERROR ###
PRODDB22        : ✗ ERROR    [04:30:22]
   Detail: Finalizado com ERRO Sun Feb 16 04:30:22 2026

### RECORDS NOT FOUND ###
PRODDB37        : ⚠ NOT FOUND

========================================
         END OF REPORT
========================================

CUSTOMIZATION

Add more databases:

Edit the LOG_FILES array in the script:

LOG_FILES=(
"/scripts/backup/NEWDB/logs/hot_bkp_NEWDB.log"
# ... other paths
)

Change the search patterns:

If your logs have a different format, adjust these lines. The default patterns are the literal messages written to the log by the backup job: Finalizado com successo (the success message) and Finalizado com ERRO (the error message).

RESULT_SUCCESS=$(tac "$LOG_FILE" | grep -E "Finalizado com successo $SEARCH_DATE" | head -n 1)
RESULT_ERROR=$(tac "$LOG_FILE" | grep -E "Finalizado com ERRO $SEARCH_DATE" | head -n 1)

Send the report by email:

Add at the end of the script:

# Send an email if there are errors
if [ $COUNT_ERROR -gt 0 ]; then
    ./check_daily_backup.sh | mail -s "ALERT: Backups with Error - $FULL_DATE" dba@example.com
fi

AUTOMATION WITH CRON

Automatic daily check:

# Edit crontab
crontab -e

# Check yesterday's backups at 8 AM and send an email if there is an error
0 8 * * * /home/oracle/dba/backup_check/check_daily_backup.sh yesterday | grep -q "Error:" && /home/oracle/dba/backup_check/check_daily_backup.sh yesterday | mail -s "Backups with Error" dba@example.com

# Daily log at 9 AM
0 9 * * * /home/oracle/dba/backup_check/check_daily_backup.sh yesterday >> /var/log/backup_check.log 2>&1

TROUBLESHOOTING

Alias does not work:

# Check whether the alias was loaded
alias | grep bkp

# If it does not show up, reload:
source ~/.bashrc

Permission denied:

chmod +x /home/oracle/dba/backup_check/check_daily_backup.sh

Incorrect log paths:

# Check whether the paths exist
ls -la /scripts/backup/*/logs/*.log

# Adjust in the script as needed

EXIT CODES

The script returns exit codes to make automation easier: - 0: All backups OK - 1: Warnings (backups not found) - 2: Errors (backups failed)

Usage:

bkp_1day
if [ $? -eq 2 ]; then
    echo "ALERT: Backups with error!"
fi

Author: DBA Team
Version: 1.0
Date: February 2026