{"id":23060381,"url":"https://github.com/drhdev/mdosnapshots","last_synced_at":"2025-10-15T11:37:32.558Z","repository":{"id":265978906,"uuid":"897025506","full_name":"drhdev/mdosnapshots","owner":"drhdev","description":"A python script allowing to do snapshots of multiple Digitalocean Droplets with doctl.","archived":false,"fork":false,"pushed_at":"2024-12-03T09:21:28.000Z","size":154,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T20:47:43.939Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drhdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-01T21:46:53.000Z","updated_at":"2024-12-03T09:21:32.000Z","dependencies_parsed_at":"2025-02-08T20:43:00.268Z","dependency_job_id":"050dba84-eb24-43e4-8796-e6c0827f41a0","html_url":"https://github.com/drhdev/mdosnapshots","commit_stats":null,"previous_names":["drhdev/mdosnapshots"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fmdosnapshots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fmdosnapshots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fmdosnapshots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fmdosnapshots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drhdev","download_url":"https://codeload.github.com/drhdev/mdosnapshots/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246952274,"owners_count":20859812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T03:12:09.925Z","updated_at":"2025-10-15T11:37:32.549Z","avatar_url":"https://github.com/drhdev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mdosnapshots - multiple Digitalocean snapshots\n\n![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)\n\n`mdosnapshots` (\"multiple Digitalocean snapshots\") is a Python-based tool designed to manage snapshots for multiple DigitalOcean Droplets. It automates the creation, retention, and deletion of snapshots, ensuring your droplets are backed up efficiently. Additionally, it integrates with Telegram to notify you of the snapshot operations' status, providing real-time updates directly to your messaging app.\n\n## Table of Contents\n\n- [Features](#features)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage](#usage)\n- [Setting Up Cronjobs](#setting-up-cronjobs)\n- [Logging](#logging)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- **Automated Snapshot Management**: Schedule regular snapshots for your DigitalOcean Droplets.\n- **Retention Policy**: Define how many recent snapshots to retain and automatically delete older ones.\n- **Telegram Notifications**: Receive real-time updates on snapshot operations via Telegram.\n- **Flexible Configuration**: Manage multiple droplets with individual settings using YAML configuration files.\n- **Logging**: Detailed logging with log rotation to monitor operations and troubleshoot issues.\n\n## Prerequisites\n\n- **Python 3.7+**\n- **DigitalOcean Account** with Droplets and API Tokens\n- **doctl**: DigitalOcean command-line tool installed and configured\n- **Telegram Bot**: A Telegram bot token and chat ID for sending notifications\n\n## Installation\n\n1. **Clone the Repository**\n\n   ```bash\n   git clone https://github.com/drhdev/mdosnapshots.git\n   cd mdosnapshots\n   ```\n\n2. **Create a Virtual Environment (Optional but Recommended)**\n\n   ```bash\n   python3 -m venv venv\n   source venv/bin/activate\n   ```\n\n3. **Install Dependencies**\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n4. **Install `doctl`**\n\n   Follow the official [doctl installation guide](https://docs.digitalocean.com/reference/doctl/how-to/install/) to install `doctl` on your system.\n\n## Configuration\n\n1. **Environment Variables**\n\n   Create a `.env` file in the root directory of the repository based on the provided `env.example`:\n\n   ```bash\n   cp env.example .env\n   ```\n\n   Edit the `.env` file to include your Telegram Bot Token and Chat ID:\n\n   ```env\n   TELEGRAM_BOT_TOKEN=your_bot_token_here\n   TELEGRAM_CHAT_ID=your_chat_id_here\n   ```\n\n2. **Droplet Configuration**\n\n   Navigate to the `configs` directory and create or edit YAML configuration files for each droplet. Example configurations are provided as `droplet1.yaml` and `droplet2.yaml`.\n\n   ```yaml\n   droplet:\n     id: \"your-digitalocean-droplet-id-1\" # e.g. 33345678\n     name: \"your-digitalocean-droplet-name-1\" # e.g. wordpress-ubuntu-s-1vcpu-1gb-nyc2-01\n     api_token: \"your_digitalocean_api_token_1\"\n     retain_last_snapshots: 3\n     delete_retries: 5\n   ```\n\n   - **id**: The unique identifier of your droplet.\n   - **name**: The name of your droplet.\n   - **api_token**: Your DigitalOcean API token with appropriate permissions.\n   - **retain_last_snapshots**: Number of recent snapshots to retain.\n   - **delete_retries**: Number of retries for deleting snapshots in case of failure.\n\n## Usage\n\n### Managing Snapshots\n\nTo manually run the snapshot management script:\n\n```bash\npython mdosnapshots.py -v\n```\n\n- **Options**:\n  - `-v`, `--verbose`: Enable verbose logging to the console.\n  - Specify specific configuration files by listing them as arguments.\n\nExample:\n\n```bash\npython mdosnapshots.py droplet1.yaml droplet2.yaml -v\n```\n\n### Sending Log Notifications to Telegram\n\nAfter running the snapshot script, use the log notifier to send the latest status to Telegram (only when Status is not \"SUCCESS\"):\n\n```bash\npython log2telegram.py -v\n```\n\n- **Options**:\n  - `-v`, `--verbose`: Enable verbose output to the console.\n  - `-d`, `--delay`: Delay in seconds between sending multiple Telegram messages (default: 10 seconds).\n\nExample:\n\n```bash\npython log2telegram.py --verbose --delay 15\n```\n\n## Setting Up Cronjobs\n\nTo automate the snapshot management and notification process, set up cronjobs that run both scripts sequentially.\n\n### Example Cronjob\n\n1. **Open the Crontab Editor**\n\n   ```bash\n   crontab -e\n   ```\n\n2. **Add the Following Cronjob**\n\n   The following example schedules the snapshot process to run daily at 2:00 AM and immediately sends a Telegram notification after snapshots are managed.\n\n   ```cron\n   0 2 * * * PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin; cd /path/to/mdosnapshots \u0026\u0026 /path/to/mdosnapshots/venv/bin/python mdosnapshots.py \u003e\u003e mdosnapshots_cron.log 2\u003e\u00261 \u0026\u0026 /path/to/mdosnapshots/venv/bin/python log2telegram.py \u003e\u003e log2telegram_cron.log 2\u003e\u00261\n   ```\n\n   - **Replace `/path/to/mdosnapshots`** with the actual path to your `mdosnapshots` repository.\n   - **Replace `/path/to/modsnapshots/venv/bin/python`** with the path to your Python executable, especially if using a virtual environment.\n   - **Logging**: The output of each script is appended to separate cron logs for troubleshooting.\n\n3. **Save and Exit**\n\n   Save the crontab file and exit the editor. The cronjob is now scheduled to run automatically.\n\n## Logging\n\n- **Snapshot Manager Log**: `mdosnapshots.log` – Logs detailed information about snapshot operations.\n- **Telegram Notifier Log**: `log2telegram.log` – Logs the activities of sending messages to Telegram.\n- **Cronjob Logs**: `mdosnapshots_cron.log` \u0026 `log2telegram_cron.log` – Capture the output of cron-executed scripts.\n\nLogs are managed with log rotation to prevent uncontrolled growth.\n\n## Contributing\n\nContributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrhdev%2Fmdosnapshots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrhdev%2Fmdosnapshots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrhdev%2Fmdosnapshots/lists"}