-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JS Fillman
committed
May 1, 2024
1 parent
3c51e98
commit 17d4f6f
Showing
2 changed files
with
134 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,39 @@ | ||
|
||
## Zip2Cloud | ||
|
||
A robust zip & upload utility for sending archives to any destination supported by [rclone](https://rclone.org/). | ||
|
||
### Features | ||
|
||
- Only uploads _completed_ archives | ||
- Compares local & remote files with md5 sums | ||
- Only deletes local files once they have been successfully uploaded | ||
- Allows keeping an arbitrary amount of zipped & unzipped backups locally for faster restore | ||
- Script only zips & uploads files that are missing from the remote location | ||
|
||
[//]: # (- Allows mixing backup files with other data) | ||
|
||
[//]: # ( - Only zips folders under the `$DUMP_BASE` directory with a date-based name e.g. `2024-04-01`) | ||
|
||
[//]: # (- Notifies on completion or error via Slack) | ||
|
||
### Operation of `zip2cloud` | ||
|
||
1. Cleans up old zip files and backup dumps based on the retention period set in the environment variables. | ||
2. Retrieves the list of remote backups and their MD5 checksums from the remote S3 bucket. | ||
3. Checks database dumps for completion by looking for a `dump_complete.txt` file in the dump's top-level directory. | ||
4. Compresses new database dumps that do not have a corresponding MD5 file in the remote S3 bucket. | ||
5. Compares the MD5 checksums of local and remote files. | ||
1. If a local file does not have a matching MD5 checksum in the remote S3 bucket, it is added to the upload list. | ||
6. If there's an MD5 mismatch between a local and a remote file, the script increments the filename of the local file and adds it to the upload list. | ||
7. Finally, it syncs all the files in the upload list to the remote S3 bucket using rclone. | ||
|
||
### Variables | ||
|
||
| Variable | Description | Default | | ||
|-----------------|---------------------------------------------------|---------| | ||
| `BUCKET` | The bucket to store the backups | | | ||
| `BUCKET_PATH` | The path within the bucket to store the backups | | | ||
| `DUMP_BASE` | The base directory for backup dumps | `/dump` | | ||
| `DUMP_RETENTION`| The number of days to keep uncompressed backups locally | | | ||
| `REMOTE` | The remote location to sync backups to | | | ||
| `SECRET` | The encryption key for 7zip | | | ||
| `SLACK_CHANNEL` | The slack channel to send notifications to | | | ||
| `SLACK_WEBHOOK` | The webhook URL for slack notifications | | | ||
| `ZIP_BASE` | The base filename, minus date, for the compressed backups | | | ||
| `ZIP_DIR` | The directory to store all compressed backups | `/zip` | | ||
| `ZIP_RETENTION` | The number of days to keep compressed backups locally | | | ||
# zip2cloud Application | ||
|
||
The `zip2cloud` application is a shell script that manages backup dumps, compresses them into zip files, compares them with existing backups in remote storage, and uploads any new or updated backups to the remote storage. | ||
|
||
## Environment Variables | ||
|
||
The script uses the following environment variables: | ||
|
||
| Variable | Description | Default | | ||
|--------------------|-----------------------------------------------------------------------|----------------------------------| | ||
| `COMPRESSION_LEVEL`| Compression level for 7z files | 0 | | ||
| `DELETE_DUMP` | Optionally deletes exports under `$DUMP_BASE` when done compressing | _Unused_ | | ||
| `DUMP_BASE` | Base directory for dumps | `/dump/full_backup` | | ||
| `DUMP_RETENTION` | Retention policy for dumps | 3 | | ||
| `REMOTE` | Remote storage details | `remote:${BUCKET}/${BUCKETPATH}` | | ||
| `SECRET` | Encryption key for 7z files | | | ||
| `SLACK_CHANNEL` | Slack channel for notifications | _Unused_ | | ||
| `SLACK_WEBHOOK` | Slack webhook for notifications | _Unused_ | | ||
| `ZIP_BASE` | Base name for zip files | `backup_full` | | ||
| `ZIP_DIR` | Directory for zip files | `/zip` | | ||
| `ZIP_RETENTION` | Retention policy for zip files | 4 | | ||
|
||
## Workflow | ||
|
||
The script performs the following steps: | ||
|
||
1. **Cleanup**: Removes old zip files and backup dumps based on the retention policies set in the environment variables. | ||
2. **Checksumming**: Retrieves a list of remote backups and downloads the MD5 checksums for each remote backup into a temporary directory. It then compares the checksums of local zip files against the remote MD5 checksums, adding any files that don't match to an upload list. | ||
3. **Create Upload List**: Verifies and updates the list of files to upload. For each file in the upload list, it compares the local and remote MD5 checksums. If there's a mismatch, it increments the filename and adds it to the final upload list. This incrementing process continues until it finds a filename that doesn't conflict with existing files in the remote storage. | ||
4. **Upload**: Uploads the files in the final upload list to the remote storage using the `rclone` command. | ||
|
||
## Dockerfile | ||
|
||
The Dockerfile for this application is based on the `alpine:latest` image and includes the necessary binaries and files for the `zip2cloud` script. The Dockerfile uses a multi-stage build process to keep the final image size small. | ||
|
||
## GitHub Actions | ||
|
||
The application uses GitHub Actions for continuous integration. The workflows are defined in the `.github/workflows/` directory and include steps for building, tagging, and pushing Docker images, as well as scanning for vulnerabilities with Trivy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters