Skip to content

improve backup database detection and container lookup - #8

Merged
x0sina merged 3 commits into
PasarGuard:mainfrom
x0sina:main
Nov 1, 2025
Merged

improve backup database detection and container lookup#8
x0sina merged 3 commits into
PasarGuard:mainfrom
x0sina:main

Conversation

@x0sina

@x0sinax0sina commented Nov 1, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling with consolidated error reporting and proper exit codes on failure.
    • Enhanced resilience to continue processing when database detection issues occur.
  • New Features

    • Better support and detection for multiple database types.
    • Error notifications now include detailed error lists and log file links for troubleshooting.

@coderabbitai

coderabbitaiBot commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Enhanced backup script with robust environment variable handling, multi-database-type detection (MariaDB, MySQL, PostgreSQL, TimescaleDB), granular container resolution, segregated local/remote database paths, consolidated error aggregation, and improved Telegram reporting with error summaries and log file links.

Changes

Cohort / File(s)Summary
Backup Command Enhancement
pasarguard.sh
Reworked backup_command with environment variable quote stripping, database detection logging, and container resolution for multiple database types; added per-database-type backup logic with root-user fallback to app-user credentials; replaced implicit success with explicit error tracking (error array), consolidated error reporting to Telegram and logs, and conditional continuation on missing database type.

Sequence Diagram

sequenceDiagram
actor User
participant Script as pasarguard.sh
participant Env as .env
participant Docker as Docker/Container
participant DB as Database
participant Log as Log File
participant Telegram as Telegram
User->>Script: Execute backup_command
Script->>Env: Load SQLALCHEMY_DATABASE_URL
Note over Script: Strip surrounding quotes,<br/>log presence/content
Script->>Script: Parse DB host & type
Script->>Docker: Resolve container ID<br/>(running or via docker-compose)
Note over Script: Attempt container resolution<br/>per DB type
Script->>Script: Detect DB type<br/>(MariaDB/MySQL/PostgreSQL/TimescaleDB)
alt DB Type Detected
Script->>DB: Collect databases
alt Local Docker Container
Note over Script: Use MYSQL_ROOT_PASSWORD<br/>or fallback credentials
Script->>DB: Attempt root-user dump
alt Root dump succeeds
Script->>Log: Log backup success
else Root dump fails
Note over Script: Collect error
Script->>DB: Attempt app-user dump
alt App-user dump succeeds
Script->>Log: Log backup with fallback
else App-user dump fails
Script->>Log: Log error
end
end
else Remote Database
Note over Script: Mark as not yet supported,<br/>record error
Script->>Log: Log error
end
else No DB Type Detected
Note over Script: Warn and skip DB backup,<br/>continue with other steps
Script->>Log: Log warning
end
Script->>Script: Aggregate all errors
alt Errors exist
Script->>Telegram: Send error summary<br/>with log file link
Script->>Log: Write final error report
Script->>User: Return exit code 1
else No errors
Script->>Telegram: Send success notification
Script->>User: Return exit code 0
end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Container resolution logic: Multi-database-type detection with fallback strategies requires careful verification for each database type (MariaDB, MySQL, PostgreSQL, TimescaleDB).
  • Error aggregation and reporting: New error array and consolidated reporting paths need validation to ensure all error conditions are properly captured and communicated.
  • Credential handling: Root-user vs. app-user fallback logic and environment variable stripping require verification for security and correctness across different database configurations.
  • Control flow changes: Transitions from implicit success to explicit error tracking and conditional skipping need careful trace-through to prevent missed failures.
  • Telegram integration changes: Error summary formatting and log file link inclusion should be validated for proper formatting and accessibility.

Poem

🐰 Backups now dance with Docker's grace,
Database types found in every place,
Errors caught and logged with care,
Telegram whispers what's been there,
Robust and wise, no more despair! 🛡️✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c4b90e and 398c783.

📒 Files selected for processing (1)
  • pasarguard.sh (5 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@x0sina
x0sina merged commit 4185831 into PasarGuard:mainNov 1, 2025
1 check was pending
@coderabbitaicoderabbitaiBot mentioned this pull request May 1, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@x0sina