Skip to content

Instantly share code, notes, and snippets.

@siteslave
Created November 10, 2024 04:04
Show Gist options
  • Save siteslave/930e039ff5c87874b0d65dda9292a6f6 to your computer and use it in GitHub Desktop.
Save siteslave/930e039ff5c87874b0d65dda9292a6f6 to your computer and use it in GitHub Desktop.

This script performs a backup of a MySQL database with the following features:

  1. Configuration:

    • Reads configuration from a specified file.
    • Supports different roles (master/slave) for database configuration.
    • Configurable backup directory, number of threads, and other settings.
  2. Password Generation:

    • Generates a random password for the zip file containing the backup.
  3. MySQL Command Check:

    • Verifies the availability of MySQL client tools (mysql and mysqldump).
  4. Backup Directory Management:

    • Creates a target directory for the backup.
    • Removes old backup directories if they exist.
  5. Table Dumping:

    • Dumps each table from the database into a SQL file.
    • Compresses each SQL file into a password-protected zip file.
    • Tracks dumped tables to support resuming interrupted backups.
  6. Log Table Filtering:

    • Optionally skips tables that are identified as log tables.
  7. Parallel Execution:

    • Uses a thread pool to dump tables in parallel for faster execution.
  8. Error Handling:

    • Logs errors and failed tables.
    • Sends error notifications via Telegram.
  9. Backup Completion:

    • Creates a final zip file containing all table dumps.
    • Writes the path of the zip file to a tracking file.
    • Sends a completion message via Telegram with backup details.
  10. Telegram Notifications:

    • Sends messages to a specified Telegram chat for important events and errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment