{"id":26769451,"url":"https://github.com/sypper-pit/lxc-backup-to-mega","last_synced_at":"2025-03-28T22:32:35.171Z","repository":{"id":254720260,"uuid":"847348491","full_name":"sypper-pit/lxc-backup-to-mega","owner":"sypper-pit","description":"LXC Container Backup Script","archived":false,"fork":false,"pushed_at":"2024-12-25T19:16:16.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-25T19:25:14.684Z","etag":null,"topics":["backup","backup-script","lxc","mega","megadrive"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sypper-pit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-25T15:16:31.000Z","updated_at":"2024-12-25T19:16:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"16f8c546-f063-4f9f-935b-ea4bc317214e","html_url":"https://github.com/sypper-pit/lxc-backup-to-mega","commit_stats":null,"previous_names":["sypper-pit/lxc-backup-to-mega"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Flxc-backup-to-mega","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Flxc-backup-to-mega/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Flxc-backup-to-mega/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sypper-pit%2Flxc-backup-to-mega/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sypper-pit","download_url":"https://codeload.github.com/sypper-pit/lxc-backup-to-mega/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246110128,"owners_count":20724995,"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":["backup","backup-script","lxc","mega","megadrive"],"created_at":"2025-03-28T22:31:39.478Z","updated_at":"2025-03-28T22:32:35.164Z","avatar_url":"https://github.com/sypper-pit.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LXC Container Backup Script\n\n#### Description\n\nThis Bash script automates the process of creating, managing, and uploading backups of LXC (Linux Containers) to MEGA cloud storage. It's designed to maintain a specified number of local backups, MEGA backups, and LXC snapshots.\n\n#### Features\n\n- **Automatic error handling**: The script uses `set -e` and a trap to exit on errors.\n- **Logging**: Provides detailed logging of each step in the backup process.\n- **Dependency checking**: Verifies the presence of required commands before execution.\n- **MEGA integration**: Automatically creates a backup folder on MEGA if it doesn't exist.\n- **Snapshot management**: Cleans up old snapshots, maintaining a specified count.\n- **Backup rotation**: Manages both local and MEGA backups, keeping only the most recent ones.\n- **Compression**: Uses `xz` compression for efficient storage and transfer.\n\n#### How It Works\n\n1. **Initialization**: \n   - Sets up error handling and logging.\n   - Checks for required commands and the existence of the specified container.\n\n2. **MEGA Setup**: \n   - Ensures a backup folder exists on MEGA. https://mega.io/ru/cmd#download\n\n3. **Snapshot Management**:\n   - Removes old snapshots, keeping only the specified number.\n\n4. **Backup Creation and Upload**:\n   - Creates a new snapshot of the container.\n   - Exports the snapshot to a compressed archive.\n   - Uploads the archive to MEGA.\n\n5. **Cleanup**:\n   - Removes old local backups and MEGA backups, maintaining the specified count.\n\n#### How to Restore a Container\n\nTo restore a container from a backup:\n\n1. **Download the backup**:\n   - Use the MEGA client to download the desired `.tar.gz.xz` file.\n\n2. **Decompress the archive**:\n   ```bash\n   xz -d \u003ccontainer_name\u003e-\u003ctimestamp\u003e.tar.gz.xz\n   ```\n\n3. **Import the container**:\n   ```bash\n   lxc import \u003ccontainer_name\u003e-\u003ctimestamp\u003e.tar.gz\n   ```\n\n4. **Start the restored container**:\n   ```bash\n   lxc start \u003ccontainer_name\u003e\n   ```\n\n#### Configuration\n\nAdjust the following variables in the script to customize the backup process:\n\n- `CONTAINER`: Name of the LXC container to backup.\n- `LOCAL_BACKUP_COUNT`: Number of local backups to keep.\n- `MEGA_BACKUP_COUNT`: Number of backups to keep on MEGA.\n- `SNAPSHOT_COUNT`: Number of snapshots to keep in LXC.\n\n#### Requirements\n\n- LXC (Linux Containers)\n- MEGA command-line tools (`mega-put`, `mega-ls`, `mega-mkdir`)\n- `xz` compression utility\n\n#### Error Handling\n\nThe script uses the `trap` command to handle errors gracefully. If an error occurs, it will display an error message and exit with a non-zero status.\n\n#### Note\n\nEnsure you have sufficient permissions and storage space both locally and on your MEGA account before running this script.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsypper-pit%2Flxc-backup-to-mega","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsypper-pit%2Flxc-backup-to-mega","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsypper-pit%2Flxc-backup-to-mega/lists"}