# Cron Tab for Daily Backup and DB Restoration

This document describes the procedure for automating MySQL database backups and restores using CronTab on a Linux-based system. The process ensures consistent backup execution and supports timely recovery in case of data loss. It reduces manual intervention and improves the reliability of metadata storage for the OvalEdge platform.

## Prerequisites

* Linux-based system with root or sudo access
* Sufficient storage space for backup files
* Basic knowledge of CronTab and shell scripting
* NFS mount (optional) for storing backups in a network location

## Steps Involved

1. Configure MySQL Database Backup

   * Log in to the MySQL server.

   * Create a directory to store backup scripts and files.

   * Create a file named mysql\_backup.sh.\
     \
     Sample Reference Screenshot:

     <div align="left"><figure><img src="/files/YN1mq7VEpiYrakXHsQRJ" alt=""><figcaption></figcaption></figure></div>

   * Add the following script to the file:

     ```
     #!/bin/bash
     # Database credentials
     user="root"
     password="<mysql root user password>"
     host="<localhost or RDS endpoint>"
     db_name="ovaledgedb"
     # Backup storage path
     backup_path="<full path where backup should be stored>"
     # Date format for filename
     date=$(date +"%d-%b-%Y")
     # Log file path
     log_file="$backup_path/backup.log"
     # Create backup directory if it does not exist
     mkdir -p "$backup_path"
     # Perform mysqldump
     echo "[$(date)] Starting backup for $db_name" >> "$log_file"
     mysqldump --user="$user" --password="$password" --host="$host" "$db_name" > "$backup_path/${db_name}-${date}.sql" 2>>"$log_file"
     if [ $? -eq 0 ]; then
         echo "[$(date)] Backup successful: ${db_name}-${date}.sql" >> "$log_file"
     else
         echo "[$(date)] Backup failed for $db_name" >> "$log_file"
     fi
     # Delete backups older than 10 days
     find "$backup_path" -name "${db_name}-*.sql" -type f -mtime +10 -exec rm -f {} \; >> "$log_file" 2>&1
     echo "[$(date)] Old backups (older than 10 days) cleaned up." >> "$log_file"

     ```

     Sample Reference Screenshot:

     <figure><img src="/files/htsUYT9kOgNFQMJV0T3H" alt=""><figcaption></figcaption></figure>

   * Update the following parameters based on the environment:
     * MySQL username and password
     * Host (local or RDS endpoint)
     * Backup directory path

   * Grant execute permission to the script:

     ```
     chmod +x mysql_backup.sh
     ```

     \
     Sample Reference Screenshot:

     <div align="left"><figure><img src="/files/H8sFVumg9hAJEHfVe3qG" alt=""><figcaption></figcaption></figure></div>

   * Run the script manually to verify execution:

     ```
     sh mysql_backup.sh
     ```

     \
     Sample Reference Screenshot:

     <figure><img src="/files/cwa3ciZ36gqM1xivTSnG" alt=""><figcaption></figcaption></figure>

   * Confirm that the backup file is created in the specified directory.

2. Schedule Backup Using CronTab
   * Open the crontab editor:

     ```
     crontab -e
     ```
   * Add the following entry to schedule daily execution at 2:00 AM:

     ```
     0 2 * * * /home/ovaledge/mysql_backup.sh >> /home/ovaledge/backup.log 2>&1
     ```

     \
     \
     Sample Reference Screenshot:

     <figure><img src="/files/y2fKoVYQclpM3MjbmsdU" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This configuration runs the backup script daily at 02:00 AM, and appends logs to the specified log file.
{% endhint %}

3. Perform MySQL Database Restoration
   * Connect to the MySQL server:

     ```
     mysql -u root -p
     ```

     \
     Sample Reference Screenshot:

     <figure><img src="/files/8MC5aJtIeYo9WuEqbs8i" alt=""><figcaption></figcaption></figure>

   * Create the database and user, and grant required permissions:

     ```
     CREATE DATABASE ovaledgedb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
     CREATE USER IF NOT EXISTS 'ovaledge'@'localhost' IDENTIFIED BY '<password>';
     CREATE USER IF NOT EXISTS 'ovaledge'@'%' IDENTIFIED BY '<password>';
     GRANT ALL ON ovaledgedb.* TO 'ovaledge'@'localhost';
     GRANT ALL ON ovaledgedb.* TO 'ovaledge'@'%';
     ```

     \
     Sample Reference Screenshot:

     <figure><img src="/files/f2EH9XxMf3nFRr3c7Cv4" alt=""><figcaption></figcaption></figure>

   * Replace with the required password.

   * Restore the database using the backup file:

     ```
     source /home/ovaledge/ovaledgedb-22-May-2025.sql
     ```

     \
     Sample Reference Screenshot:

     <figure><img src="/files/dLYy23QUn4omghUGl7Rn" alt=""><figcaption></figcaption></figure>

   * Verify that the database restoration is completed successfully.
4. Update Configuration and Start Services
   * Update the oasis.properties file with the correct database details.\
     \
     Sample Reference Screenshot:

     <figure><img src="/files/XwhQyGEty2gME5ZA3hXA" alt=""><figcaption></figcaption></figure>

   * Start the Tomcat service:

     ```
     sudo systemctl start tomcat
     ```

     \
     Sample Reference Screenshot:

     <figure><img src="/files/f40RIzAePrs5PpFgsdzZ" alt=""><figcaption></figcaption></figure>

   * Verify that the application is accessible after a few minutes.

***

Copyright © 2026, OvalEdge LLC, Peachtree Corners, GA, USA.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ovaledge.com/release8.1/deployment-and-maintenance/backup/cron-tab-for-daily-backup-and-db-restoration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
