{"id":20382108,"url":"https://github.com/drhdev/dosnapshots","last_synced_at":"2025-07-27T17:04:20.893Z","repository":{"id":242414964,"uuid":"809487216","full_name":"drhdev/dosnapshots","owner":"drhdev","description":"A simple Python script to create snapshots of Digital Ocean droplets using doctl with tokens via the DO API","archived":false,"fork":false,"pushed_at":"2024-11-02T16:09:11.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T22:41:59.885Z","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-06-02T20:30:21.000Z","updated_at":"2024-11-02T16:09:14.000Z","dependencies_parsed_at":"2024-06-02T22:06:51.253Z","dependency_job_id":"6f2a94b3-bafc-46ca-8223-656c088e12b9","html_url":"https://github.com/drhdev/dosnapshots","commit_stats":null,"previous_names":["drhdev/dosnapshots"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drhdev/dosnapshots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fdosnapshots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fdosnapshots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fdosnapshots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fdosnapshots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drhdev","download_url":"https://codeload.github.com/drhdev/dosnapshots/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drhdev%2Fdosnapshots/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267392336,"owners_count":24079916,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-15T02:16:33.472Z","updated_at":"2025-07-27T17:04:20.857Z","avatar_url":"https://github.com/drhdev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dosnapshots\n\n`dosnapshots.py` is a Python script designed to manage DigitalOcean snapshots for a specified Droplet. The script automates the creation and deletion of snapshots based on a configurable retention policy, ensuring an efficient and organized backup system.\n\n## Key Features\n\n### Snapshot Creation\n\n- The script creates a snapshot of the specified DigitalOcean Droplet using the `doctl` command-line tool.\n- Snapshots are named with the droplet name followed by a timestamp for easy identification.\n  \n### Snapshot Retention\n\n- The script enforces a retention policy that retains a specified number of recent snapshots.\n- Older snapshots that do not fit within the retention policy are automatically deleted.\n\n### Detailed Logging\n\n- Logs detailed information about each command executed, including success messages and any errors encountered.\n- Ensures sensitive information, such as the DigitalOcean API token, is masked in the logs.\n- Final status messages provide a summary of each run, including the hostname, timestamp, snapshot name, and the total number of snapshots retained.\n\n## Configuration\n\nThe script is highly configurable through environment variables set in the `.env` file:\n\n- **DROPLET_ID**: The unique identifier of the DigitalOcean Droplet to manage.\n- **DROPLET_NAME**: A prefix for snapshot names to easily identify them.\n- **DO_API_TOKEN**: The DigitalOcean API token used for authentication with the `doctl` tool.\n\n### API Token Scope\n\nEnsure that your API token has the correct scope with sufficient permissions to create, list, and delete snapshots. Instructions on how to set up personal access tokens with the required permissions can be found in the DigitalOcean documentation: [Create Personal Access Token](https://docs.digitalocean.com/reference/api/create-personal-access-token/).\n\n### Retention Policy\n\n- **RETAIN_LAST_SNAPSHOTS**: Number of recent snapshots to retain.\n- **DELETE_RETRIES**: Number of retries when attempting to delete a snapshot.\n\n### Log File\n\n- Logs are stored in the same directory as the script, with detailed logging of every operation.\n\n### Path to `doctl`\n\n- The full path to the `doctl` binary should be configured correctly, usually `/usr/local/bin/doctl` if installed manually.\n- To manually install `doctl`, use these commands:\n- Download to a temporary directory:\n  ```bash\n  sudo curl -sL https://github.com/digitalocean/doctl/releases/download/v1.117.0/doctl-1.117.0-linux-amd64.tar.gz -o /tmp/doctl.tar.gz\n  ```\n- Extract the binary from the tar.gz archive\n  ```bash\n  sudo tar -xzf /tmp/doctl.tar.gz -C /usr/local/bin doctl\n  ```\n- Make the binary executable\n  ```bash\n  sudo chmod +x /usr/local/bin/doctl\n  ```\n- After running the command, check the version:\n  ```bash\n  doctl version\n  ```\n- To find out where `doctl` is installed on your system, you can use the following command in the terminal:\n  ```bash\n  which doctl\n  ```\n\nThis command will display the path to the `doctl` executable if it is available in your system's PATH.\n\n## Usage Instructions\n\n### Clone the Repository\n\nClone the `dosnapshots` repository to your home directory:\n\n```bash\nmkdir -p /home/user/python\ncd /home/user/python\ngit clone https://github.com/drhdev/dosnapshots.git\ncd dosnapshots\n```\n\n### Setup a Virtual Environment\n\nCreate and activate a virtual environment:\n\n```bash\npython3 -m venv venv\nsource venv/bin/activate\npip install -r requirements.txt\n```\n\n### Configure Environment Variables\n\nCreate a `.env` file in the `/home/user/python/dosnapshots` directory with your DigitalOcean configuration:\n\n```plaintext\n# .env file\nDROPLET_ID=your_droplet_id\nDROPLET_NAME=your_droplet_name\nDO_API_TOKEN=your_api_token\n```\n\n### Test the Script Manually on the Command Line\n\nActivate the virtual environment and run the script:\n\n```bash\nsource /home/user/python/dosnapshots/venv/bin/activate\npython /home/user/python/dosnapshots/dosnapshots.py\n```\n\n### Check Logs\n\nLogs are stored in the same directory as the script. You can view them with:\n\n```bash\ncat /home/user/python/dosnapshots/dosnapshots.log\n```\n\n### Set Up a Cron Job\n\nEdit your crontab to schedule the script to run at a specific time (e.g., daily at 2 AM):\n\n```bash\ncrontab -e\n```\n\nAdd the following line:\n\n```bash\n0 2 * * * /bin/bash -c 'source /home/user/python/dosnapshots/venv/bin/activate \u0026\u0026 python /home/user/python/dosnapshots/dosnapshots.py' \u003e /home/user/python/dosnapshots/dosnapshots.log 2\u003e\u00261\n```\n\nBy following these steps and configurations, `dosnapshots.py` helps maintain a systematic backup strategy for your DigitalOcean Droplets, ensuring data is securely and efficiently managed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrhdev%2Fdosnapshots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrhdev%2Fdosnapshots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrhdev%2Fdosnapshots/lists"}