diff options
author | crupest <crupest@outlook.com> | 2022-11-23 19:22:37 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-11-23 19:22:37 +0800 |
commit | f083272356417be74a5864d5ef6cfb1878558826 (patch) | |
tree | 6a489c787c073e4b4bc2b722759c098899bfea15 /docker | |
parent | fc2b0e84cc359e45c09e81135702babc2284dfb1 (diff) | |
download | crupest-f083272356417be74a5864d5ef6cfb1878558826.tar.gz crupest-f083272356417be74a5864d5ef6cfb1878558826.tar.bz2 crupest-f083272356417be74a5864d5ef6cfb1878558826.zip |
Replace rclone with coscli.
Diffstat (limited to 'docker')
-rw-r--r-- | docker/auto-backup/Dockerfile | 12 | ||||
-rwxr-xr-x | docker/auto-backup/daemon.bash | 30 | ||||
-rwxr-xr-x | docker/auto-backup/install-coscli.bash | 17 |
3 files changed, 44 insertions, 15 deletions
diff --git a/docker/auto-backup/Dockerfile b/docker/auto-backup/Dockerfile index a826f4a..7df267c 100644 --- a/docker/auto-backup/Dockerfile +++ b/docker/auto-backup/Dockerfile @@ -1,11 +1,15 @@ +FROM alpine:latest AS coscli-downloader +RUN apk add --no-cache bash curl jq +COPY install-coscli.bash /install-coscli.bash +RUN /install-coscli.bash + FROM alpine:latest -RUN apk add --no-cache coreutils bash tar xz rclone -ARG CRUPEST_AUTO_BACKUP_BUCKET_NAME +RUN apk add --no-cache coreutils bash tar xz yq ARG CRUPEST_AUTO_BACKUP_INIT_DELAY=0 ARG CRUPEST_AUTO_BACKUP_INTERVAL=1d ENV CRUPEST_AUTO_BACKUP_INIT_DELAY=${CRUPEST_AUTO_BACKUP_INIT_DELAY} ENV CRUPEST_AUTO_BACKUP_INTERVAL=${CRUPEST_AUTO_BACKUP_INTERVAL} -ENV CRUPEST_AUTO_BACKUP_BUCKET_NAME=${CRUPEST_AUTO_BACKUP_BUCKET_NAME} +COPY --from=coscli-downloader /coscli /coscli COPY daemon.bash /daemon.bash -VOLUME [ "/data", "/config/rclone/rclone.conf" ] +VOLUME [ "/data", "/root/.cos.yaml" ] ENTRYPOINT [ "/daemon.bash" ] diff --git a/docker/auto-backup/daemon.bash b/docker/auto-backup/daemon.bash index 33708ee..6a39fa5 100755 --- a/docker/auto-backup/daemon.bash +++ b/docker/auto-backup/daemon.bash @@ -8,18 +8,23 @@ if [[ $EUID -ne 0 ]]; then exit 1 fi -# Check if CRUPEST_AUTO_BACKUP_BUCKET_NAME is defined. -if [[ -z "$CRUPEST_AUTO_BACKUP_BUCKET_NAME" ]]; then - echo "CRUPEST_AUTO_BACKUP_BUCKET_NAME is not defined or empty" - exit 1 -fi - -rclone --version +/coscli --version # Check xz and tar xz --version tar --version +bucket_yaml=$(/coscli config show | yq ".buckets[] | select(.alias == \"crupest-backup\")") + +# check bucket_yaml is not empty +if [[ -z "$bucket_yaml" ]]; then + echo "Bucket crupest-backup not found. Please check your coscli config." 1>&2 + exit 1 +fi + +bucket_name=$(echo "$bucket_yaml" | yq ".name") +bucket_region=$(echo "$bucket_yaml" | yq ".region") + function backup { # Output "Begin backup..." in yellow and restore default echo -e "\e[0;103m\e[K\e[1mBegin backup..." "\e[0m" @@ -33,12 +38,15 @@ function backup { tar -cJf /tmp/data.tar.xz -C / data # Output /tmp/data.tar.xz size - du -h /tmp/data.tar.xz + du -h /tmp/data.tar.xz | cut -f1 | xargs echo "Size of data.tar.xz:" + + destination="cos://crupest-backup/$current_time.tar.xz" + echo "Use coscli to upload data to $destination ..." + echo "Bucket name: $bucket_name" + echo "Bucket region: $bucket_region" - destination="mycos:$CRUPEST_AUTO_BACKUP_BUCKET_NAME/$current_time.tar.xz" - echo "Use rclone to upload data to $destination ..." # upload to remote - rclone -vv copyto /tmp/data.tar.xz "$destination" + /coscli cp /tmp/data.tar.xz "$destination" echo "Remove tmp file..." # remove tmp diff --git a/docker/auto-backup/install-coscli.bash b/docker/auto-backup/install-coscli.bash new file mode 100755 index 0000000..d3a45b0 --- /dev/null +++ b/docker/auto-backup/install-coscli.bash @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -e + +# Check I'm root. +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +download_url=$(curl -s https://api.github.com/repos/tencentyun/coscli/releases/latest | jq -r ".assets[] | select(.name | test(\"coscli-linux\")) | .browser_download_url") + +curl -L -o /coscli "$download_url" + +chmod +x /coscli + +/coscli --version |