-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOCKER] Add rclone-gdrive-backup (#57)
- Loading branch information
1 parent
ec76fca
commit 8ff21a4
Showing
4 changed files
with
120 additions
and
7 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
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 | ||
``` |
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 |
---|---|---|
@@ -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!" |