-
Notifications
You must be signed in to change notification settings - Fork 5
MongoDB backup/import bot with PyTDBot integration #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis pull request implements a Telegram bot for MongoDB backup and restore operations using the PyTDBot library. The core functionality is achieved by wrapping File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @AshokShau - I've reviewed your changes - here's some feedback:
- Consider replacing
create_subprocess_shellwithcreate_subprocess_execfor safer execution of external commands. - Ensure temporary directories created during ZIP file imports are cleaned up after the restore operation.
- Consider restricting the
/mongocommand to authorized users (e.g., usingOWNER_IDfrom config) to prevent unintended database access.
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| stderr=asyncio.subprocess.PIPE | ||
| ) | ||
|
|
||
| stdout, stderr = await proc.communicate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logger instead of print for error reporting.
run_mongodump prints errors directly; switching to our logger ensures consistency and better log level control.
Suggested implementation:
import asyncio
import logging
logger = logging.getLogger(__name__) logger.error(f"[mongodump error]: {stderr.decode()}")• If your file already imports logging or defines a logger instance, adjust the changes accordingly by only replacing the print() with logger.error().
| if shutil.which("mongodump") is None: | ||
| print("❌ mongodump is not installed. Please install MongoDB tools:") | ||
| print("• Arch: yay -S mongodb-tools-bin") | ||
| print("• Ubuntu/Docker: use official .tgz tools from https://www.mongodb.com/try/download/database-tools") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider handling missing mongodump as an error rather than just printing.
Instead of continuing, exit or raise an exception to stop execution and avoid later failures.
| if shutil.which("mongodump") is None: | |
| print("❌ mongodump is not installed. Please install MongoDB tools:") | |
| print("• Arch: yay -S mongodb-tools-bin") | |
| print("• Ubuntu/Docker: use official .tgz tools from https://www.mongodb.com/try/download/database-tools") | |
| if shutil.which("mongodump") is None: | |
| raise RuntimeError("❌ mongodump is not installed. Please install MongoDB tools:\n• Arch: yay -S mongodb-tools-bin\n• Ubuntu/Docker: use official .tgz tools from https://www.mongodb.com/try/download/database-tools") |
| @@ -0,0 +1,64 @@ | |||
| # MongoDB Backup Bot 📦 | |||
|
|
|||
| A Telegram bot built using [PyTDBot](https://github.com/pytdbot/client) to backup and restore MongoDB databases. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Consider using 'to back up' instead of 'to backup'.
Use “to back up” (two words) as the standard verb form, e.g., “...to back up and restore...”.
| A Telegram bot built using [PyTDBot](https://github.com/pytdbot/client) to backup and restore MongoDB databases. | |
| A Telegram bot built using [PyTDBot](https://github.com/pytdbot/client) to back up and restore MongoDB databases. |
| """Extract MongoDB URI from text.""" | ||
| uri_pattern = r"(mongodb(?:\+srv)?:\/\/[a-zA-Z0-9\-._~:\/?#[\]@!$&'()*+,;=]+)" | ||
| match = re.search(uri_pattern, text) | ||
| return match.group(0) if match else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Replace m.group(x) with m[x] for re.Match objects (use-getitem-for-re-match-groups)
| return match.group(0) if match else None | |
| return match[0] if match else None |
Summary by Sourcery
Create a Telegram bot for MongoDB backup and restore operations using PyTDBot, enabling users to create and import database backups directly through Telegram commands
New Features:
Enhancements:
Deployment:
Documentation: