Skip to content

Commit

Permalink
[DOCKER] Add rclone-gdrive-backup (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-lancini authored Jul 2, 2021
1 parent ec76fca commit 8ff21a4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
15 changes: 8 additions & 7 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ All these images are pushed to [Github Container Registry](https://github.com/ma

## Images

| Image | Description | Pull | Status |
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [ansible-worker](ansible-worker/) | Alpine with Ansible, OpenSSH, and sshpass preinstalled | `ghcr.io/marco-lancini/ansible-worker:latest` | ![[DOCKER IMAGE] Ansible Worker](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Ansible%20Worker/badge.svg) |
| [github-changelog-generator](github-changelog-generator/) | Docker image for [github-changelog-generator](https://github.com/github-changelog-generator/github-changelog-generator) | `ghcr.io/marco-lancini/github-changelog-generator:latest` | ![[DOCKER IMAGE] Latex](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Github-ChangeLog-Generator/badge.svg) |
| [latex](latex/) | Alpine with texlive preinstalled | `ghcr.io/marco-lancini/latex:latest` | ![[DOCKER IMAGE] Latex](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Latex/badge.svg) |
| [markserv](markserv/) | Image for [Markserv](https://github.com/markserv/markserv) | `ghcr.io/marco-lancini/markserv:latest` | ![[DOCKER IMAGE] Markserv](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Markserv/badge.svg) |
| [nomad](nomad/) | Image for HashiCorp Nomad | `ghcr.io/marco-lancini/nomad:latest` | ![[DOCKER IMAGE] Nomad](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Nomad/badge.svg) |
| Image | Description | Pull | Status |
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [ansible-worker](ansible-worker/) | Alpine with Ansible, OpenSSH, and sshpass preinstalled | `ghcr.io/marco-lancini/ansible-worker:latest` | ![[DOCKER IMAGE] Ansible Worker](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Ansible%20Worker/badge.svg) |
| [github-changelog-generator](github-changelog-generator/) | Docker image for [github-changelog-generator](https://github.com/github-changelog-generator/github-changelog-generator) | `ghcr.io/marco-lancini/github-changelog-generator:latest` | ![[DOCKER IMAGE] Latex](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Github-ChangeLog-Generator/badge.svg) |
| [latex](latex/) | Alpine with texlive preinstalled | `ghcr.io/marco-lancini/latex:latest` | ![[DOCKER IMAGE] Latex](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Latex/badge.svg) |
| [markserv](markserv/) | Image for [Markserv](https://github.com/markserv/markserv) | `ghcr.io/marco-lancini/markserv:latest` | ![[DOCKER IMAGE] Markserv](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Markserv/badge.svg) |
| [nomad](nomad/) | Image for HashiCorp Nomad | `ghcr.io/marco-lancini/nomad:latest` | ![[DOCKER IMAGE] Nomad](https://github.com/marco-lancini/utils/workflows/%5BDOCKER%20IMAGE%5D%20Nomad/badge.svg) |
| [python-github-backup](python-github-backup/) | Image for a customised version of the [python-github-backup](https://github.com/josegonzalez/python-github-backup) repo, as described in [Automated Github Backups with ECS and S3](https://www.marcolancini.it/2021/blog-github-backups-with-ecs/) | N/A |
| [rclone-gdrive-backup](rclone-gdrive-backup/) | Image for backing up GDrive via rclone, as described in [Automated GDrive Backups with ECS and S3](https://www.marcolancini.it/2021/blog-gdrive-backups-with-ecs) | N/A |
8 changes: 8 additions & 0 deletions docker/rclone-gdrive-backup/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y curl unzip zip
# I know, I know...
RUN curl https://rclone.org/install.sh | bash

WORKDIR /src
COPY docker/rclone-gdrive-backup/rclone-run.sh /src
15 changes: 15 additions & 0 deletions docker/rclone-gdrive-backup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# rclone GDrive Backup

Docker image for backing up GDrive via rclone, as described in [Automated GDrive Backups with ECS and S3](https://www.marcolancini.it/2021/blog-gdrive-backups-with-ecs/).


## rclone-run

The script can be used to backup a GDrive folder:

```bash
export GDRIVE_RCLONE_CONFIG=<...>
export OUTPUT_S3=<...>

rclone-run.sh
```
89 changes: 89 additions & 0 deletions docker/rclone-gdrive-backup/rclone-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#! /bin/bash

# ==============================================================================
# CONFIG
# ==============================================================================
OUTPUT_DIRECTORY="/tmp/efs/output/"
ZIP_DIRECTORY="/tmp/efs/zip/"

RCLONE_CONFIG_PATH="/src/rclone.conf"
RCLONE_FOLDER_GDRIVE="gdrive:"
RCLONE_FOLDER_S3="s3:"
RCLONE_DEBUG="-vv --dump bodies --retries 1"

#
# ENV VARS
#
VAR_GDRIVE_RCLONE_CONFIG=$GDRIVE_RCLONE_CONFIG
VAR_OUTPUT_S3=$OUTPUT_S3

# ==============================================================================
# UTILS
# ==============================================================================
function cleanup() {
echo "[*] Cleaning up EFS: ${OUTPUT_DIRECTORY}"
rm -rf $OUTPUT_DIRECTORY

echo "[*] Cleaning up EFS: ${ZIP_DIRECTORY}"
rm -rf $ZIP_DIRECTORY
}

# ==============================================================================
# RUN
# ==============================================================================
#
# Setup folders
#
echo "[*] Cleaning up folders..."
cleanup

echo "[*] Creating output directory: ${OUTPUT_DIRECTORY}"
mkdir -p $OUTPUT_DIRECTORY

echo "[*] Creating zip directory: ${ZIP_DIRECTORY}"
mkdir -p $ZIP_DIRECTORY

#
# Retrieve config
#
echo "[*] Fetching rclone config file..."
echo "$VAR_GDRIVE_RCLONE_CONFIG" > $RCLONE_CONFIG_PATH

#
# Run rclone
#
cmd="rclone --config ${RCLONE_CONFIG_PATH} --drive-acknowledge-abuse copy ${RCLONE_FOLDER_GDRIVE}/ ${OUTPUT_DIRECTORY}"
echo "[*] Running rclone: ${cmd}"
$cmd

if [ $? -ne 0 ]; then
echo "[ERROR] Backing up GDrive failed"
cleanup
exit 1
else
echo "[*] Ingestion complete"
fi

#
# Zip data
#
today_date=$(date +'%Y-%m-%d')
zip_name="${today_date}_gdrive_backup.zip"
fname="${ZIP_DIRECTORY}${zip_name}"

echo "[*] Zipping output folder: ${fname}"
zip -rq $fname $OUTPUT_DIRECTORY

#
# Sync to S3
#
echo "[*] Uploading ZIP to S3: ${VAR_OUTPUT_S3}/${zip_name}"
rclone --config ${RCLONE_CONFIG_PATH} copy $fname ${RCLONE_FOLDER_S3}${VAR_OUTPUT_S3}

#
# Cleanup
#
echo "[*] Cleaning up folders..."
cleanup

echo "[!] Completed!"

0 comments on commit 8ff21a4

Please sign in to comment.