1. Database Backup and Restore

You have two options for backing up your database: an UI-based approach and a manual command-line procedure.

Option A: Backup via the Code Quality UI

This is the recommended method for creating regular, scheduled backups.

  1. Start Your Code Quality Instance: Ensure your Docker container is running with the correct volume mappings. The most important mapping is for the data directory, which is where your backups will be stored.
    • Volume Mapping: Backups are saved to the /opt/gamma_data directory inside the Docker container. This directory is mapped to a location on your host machine (e.g.,/home/${USER}/BrowserStackCodeQuality/gamma_data) so the files are easily accessible.
    • Explanation: The /home/${USER}/BrowserStackCodeQuality/gamma_data:/opt/gamma_data
      part of the command maps the /opt/gamma_data directory inside the container to /home/${USER}/BrowserStackCodeQuality/gamma_data on your host machine. This is where your backup files will be saved.
  2. Enable and Schedule in the UI:
    • Log in to your Code Quality instance.
    • Go to Settings.
    • Look for the Backup section.
    • Enable the backup feature and set a schedule (e.g., daily, weekly).
  3. Retrieve the Backup Files
    After the scheduled backup runs, navigate to the host directory you mapped in the Docker command (e.g., /home/${USER}/BrowserStackCodeQuality/gamma_data). You’ll find a set of .sql files. For restoration, you will need to locate the files with the same timestamp, for example: embold_database_backup_07092023_102900.tar.gz

Option B: Manual Backup via the Command-line Script

This method is for a one-time, on-demand backup.

  1. Run the Backup Script
    Open your terminal on your host machine and run the following command, replacing <container_name_or_id> with your actual container name or ID.
    docker exec -it <container_name_or_id> /opt/gamma/gamma_ui/dbscripts/scripts/backup_restore.sh
    Note: The docker exec command allows you to execute commands inside a running container without entering an interactive shell.to get a shell inside the running container.
  2. Follow the On-Screen Prompts:
    • The script will display a menu. You must enter the correct letters to proceed.
    • First Prompt:Enter choice (B/R):
      • Type B for Backup and press Enter.
    • Second Prompt:Enter choice (D/F):
      • Type D for Database and press Enter.
  3. Confirm Backup Location:
    • The script will show you the progress and confirm the backup location.
    • Expected Output: Backing up databases to /opt/gamma_data/backup/db ...
    • Backup completed! Files saved in /opt/gamma_data/backup/db
    • Your backup files are now saved inside the container at /opt/gamma_data/backup/db. You can retrieve them from the mapped host directory.

3. Database Restore

This process uses a command-line script to restore the database from a backup.

⚠️ Warning: This process will overwrite your current database. It is strongly recommended to perform a new backup of your current database before proceeding with a restore.

Prerequisites

The restore script expects the backup files to be located in a specific directory: /opt/gamma_data/backup/db inside the container. Since this location is mapped to your host machine, you must ensure the backup files you want to restore are present in your host’s mapped directory (/home/${USER}/BrowserStackCodeQuality/gamma_data/backup/db).

  • If you manually created a backup, it should already be in this location.
  • If you have a backup from a different source, you must place the .sql backup files into the /home/${USER}/BrowserStackCodeQuality/gamma_data/backup/db directory on your host machine.
  • If your backup file is in .tar.gz format (from a UI-based backup), you must first extract the .sql files before placing them in the restore directory.

Run the Restore Script

Open your terminal on your host machine and run the following command, replacing <container_name_or_id> with your actual container name or ID.
docker exec -it <container_name_or_id> /opt/gamma/gamma_ui/dbscripts/scripts/backup_restore.sh

Step 3: Follow the On-Screen Prompts

  1. First Prompt:Enter choice (B/R):
    • Type R for Restore and press Enter.
  2. Second Prompt:Enter choice (D/F):
    • Type D for Database and press Enter.
  3. File Selection: The script will automatically detect the .sql files in the restore directory and list them.
    • Expected Output:Available backups in /opt/gamma_data/backup/db: 1) gamma_database_backup_07092023_102900.sql 2) corona_database_backup_07092023_102900.sql Select Gamma backup file:
    • Enter the number: Type the number corresponding to the gamma file (2 in this example) and press Enter.
    • Enter the number: Type the number corresponding to the corona file (1 in this example) and press Enter.
  4. Confirm Restore: The script will begin the restore process.
    • Expected Output:→ Restoring databases… Database restore completed!