Skip to content

Commit

Permalink
Merge pull request #3 from dantebarba/pfidr34/docker-rclone
Browse files Browse the repository at this point in the history
Update my docker-rclone fork with pfidr34 fork because bcardiff is outdated and not maintained.
  • Loading branch information
dantebarba authored Jul 14, 2023
2 parents 2ee0220 + 831432b commit ba0367a
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 39 deletions.
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
ARG BASE=alpine:3.9
ARG BASE=alpine:latest
FROM ${BASE}

LABEL maintainer="Brian J. Cardiff <bcardiff@gmail.com>"
LABEL maintainer="pfidr"

ARG RCLONE_VERSION=current
ARG ARCH=amd64
ENV SYNC_SRC=
ENV SYNC_DEST=
ENV SYNC_OPTS=-v
ENV SYNC_OPTS_EVAL=
ENV SYNC_ONCE=
ENV RCLONE_CMD=sync
ENV RCLONE_DIR_CMD=ls
ENV RCLONE_DIR_CMD_DEPTH=-1
ENV RCLONE_DIR_CHECK_SKIP=
ENV RCLONE_OPTS="--config /config/rclone.conf"
ENV OUTPUT_LOG=
ENV ROTATE_LOG=
ENV CRON=
ENV CRON_ABORT=
ENV FORCE_SYNC=
ENV CHECK_URL=
ENV FAIL_URL=
ENV HC_LOG=
ENV TZ=
ENV COMMAND=sync
ENV UID=
ENV GID=

RUN apk -U add ca-certificates fuse wget dcron tzdata \
&& rm -rf /var/cache/apk/*
RUN apk --no-cache add ca-certificates fuse wget dcron tzdata

RUN URL=http://downloads.rclone.org/${RCLONE_VERSION}/rclone-${RCLONE_VERSION}-linux-${ARCH}.zip ; \
URL=${URL/\/current/} ; \
Expand All @@ -33,6 +42,7 @@ COPY sync.sh /
COPY sync-abort.sh /

VOLUME ["/config"]
VOLUME ["/logs"]

ENTRYPOINT ["/entrypoint.sh"]

Expand Down
2 changes: 2 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Copyright 2019 Pfidr34

Copyright 2017 Brian J. Cardiff

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand Down
133 changes: 122 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,138 @@ A first run of the container can help in the creation of the file, but feel free

```
$ mkdir config
$ docker run --rm -it -v $(pwd)/config:/config bcardiff/rclone
$ docker run --rm -it -v $(pwd)/config:/config pfidr/rclone
```

### Perform sync in a daily basis

A few environment variables allow you to customize the behavior of the sync:
A few environment variables allow you to customize the behavior of rclone:

* `COMMAND` `rclone` command, e.g `sync`, `copy`, `move`.
Defaults to `sync`
* `SYNC_SRC` source location for `rclone sync` command
* `SYNC_DEST` destination location for `rclone sync` command
* `CRON` crontab schedule `0 0 * * *` to perform sync every midnight
* `SYNC_SRC` source location for `rclone sync/copy/move` command. Directories with spaces should be wrapped in single quotes.
* `SYNC_DEST` destination location for `rclone sync/copy/move` command. Directories with spaces should be wrapped in single quotes.
* `SYNC_OPTS` additional options for `rclone sync/copy/move` command. Defaults to `-v`
* `SYNC_OPTS_EVAL` further additional options for `rclone sync/copy/move` command. The variables and commands in the string are first interpolated like in a shell. The interpolated string is appended to SYNC_OPTS. That means '--backup-dir /old\`date -I\`' first evaluates to '--backup-dir /old2019-09-12', which is then appended to SYNC_OPTS. The evaluation happens immediately before rclone is called.
* `SYNC_ONCE` set variable to only run the sync one time and then exit the container
* `RCLONE_CMD` set variable to `sync` `copy` or `move` when running rclone. Defaults to `sync`
* `RCLONE_DIR_CMD` set variable to `ls` or `lsf` for source directory check style. Defaults to `ls`
* `RCLONE_DIR_CMD_DEPTH` set the limit of the recursion depth to this. Defaults to `-1` (rclone default)
* `RCLONE_DIR_CHECK_SKIP` set variable to skip source directory check before sync. *Use with caution*
* `CRON` crontab schedule `0 0 * * *` to perform sync every midnight. Also supprorts cron shortcuts: `@yearly` `@monthly` `@weekly` `@daily` `@hourly`
* `CRON_ABORT` crontab schedule `0 6 * * *` to abort sync at 6am
* `FORCE_SYNC` set variable to perform a sync upon boot
* `CHECK_URL` [healthchecks.io](https://healthchecks.io) url or similar cron monitoring to perform a `GET` after a successful sync
* `FAIL_URL` Fail URL to perform a `GET` after unsuccessful execution. Default: `CHECK_URL` with appended "/fail" at the end
* `SYNC_OPTS` additional options for `rclone sync` command. Defaults to `-v`
* `TZ` set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to use for the cron and log `America/Argentina/Buenos_Aires`
* `FAIL_URL` Fail URL to perform a `GET` after unsuccessful execution. By default this is `CHECK_URL` with appended "/fail" at the end
* `HC_LOG` set variable to send log data to healthchecks.io. `OUTPUT_LOG` must also be set.
* `OUTPUT_LOG` set variable to output log file to /logs
* `ROTATE_LOG` set variable to delete logs older than specified days from /logs
* `TZ` set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to use for the cron and log `America/Chicago`
* `UID` set variable to specify user to run rclone as. Must also use GID.
* `GID` set variable to specify group to run rclone as. Must also use UID.

**When using UID/GID the config and/or logs directory must be writeable by this UID**

```bash
$ docker run --rm -it -v $(pwd)/config:/config -v /path/to/source:/source -e SYNC_SRC="/source" -e SYNC_DEST="dest:path" -e TZ="America/Argentina/Buenos_Aires" -e CRON="0 0 * * *" -e CRON_ABORT="0 6 * * *" -e FORCE_SYNC=1 -e CHECK_URL=https://hchk.io/hchk_uuid bcardiff/rclone
$ docker run --rm -it -v $(pwd)/config:/config -v /path/to/source:/source -e SYNC_SRC="/source" -e SYNC_DEST="dest:path" -e TZ="America/Chicago" -e CRON="0 0 * * *" -e CRON_ABORT="0 6 * * *" -e FORCE_SYNC=1 -e CHECK_URL=https://hchk.io/hchk_uuid pfidr/rclone
```

See [rclone sync docs](https://rclone.org/commands/rclone_sync/) for source/dest syntax and additional options.

## Changelog

+ **07/06/2023:**
* Update to latest Rclone (v1.63.0)
+ **07/18/2022:**
* Update to latest Rclone (v1.59.0)
+ **04/25/2022:**
* Display exit code in console output
* Fix issue with healthcheck
* Update to latest Rclone (v1.58.0)
+ **11/18/2021:**
* Update to latest Rclone (v1.57.0)
+ **10/04/2021:**
* Update to latest Rclone (v1.56.2)
+ **09/27/2021:**
* Update to latest Rclone (v1.56.1)
+ **08/25/2021:**
* Update to latest Rclone (v1.56.0)
+ **06/25/2021:**
* Update to latest Rclone (v1.55.1)
+ **06/25/2021:**
* Update to latest Rclone (v1.55.0)
+ **03/10/2021:**
* Update to latest Rclone (v1.54.1)
+ **02/04/2021:**
* Update to latest Rclone (v1.54.0)
+ **01/22/2021:**
* Update to latest Rclone (v1.53.4)
+ **11/23/2020:**
* Update to latest Rclone (v1.53.3)
+ **10/28/2020:**
* Update to latest Rclone (v1.53.2)
+ **09/13/2020:**
* Update to latest Rclone (v1.53.1)
+ **09/05/2020:**
* Update to latest Rclone (v1.53.0)
+ **08/31/2020:**
* Add ability to send log data to healthchecks.io - See `HC_LOG` environment variable
+ **08/20/2020:**
* Update to latest Rclone (v1.52.3)
+ **06/25/2020:**
* Update to latest Rclone (v1.52.2)
+ **06/11/2020:**
* Update to latest Rclone (v1.52.1)
+ **05/28/2020:**
* Eval the entire rclone command
* Modify how rclone errors are interpreted when checking if source directory is empty
+ **05/27/2020:**
* Update to latest Rclone (v1.52.0)
* Add `RCLONE_DIR_CMD_DEPTH` option to declare recursion depth when checking if `SYNC_SRC` is empty
* Move call to signal start of healthchecks.io further up in the sync process
* Change when logs are deleted to make sure an active log is not deleted
+ **05/18/2020:**
* Modify how rclone errors are interpreted when passing results to healthchecks.io
+ **05/17/2020:**
* Handle spaces in `SYNC_SRC` and `SYNC_DEST`
+ **02/01/2020:**
* Update to latest Rclone (v1.51.0)
+ **11/20/2019:**
* Update to latest Rclone (v1.50.2)
+ **11/18/2019:**
* Add support for UID/GID
+ **11/06/2019:**
* Update to latest Rclone (v1.50.1)
+ **10/27/2019:**
* Update to latest Rclone (v1.50.0)
+ **10/07/2019:**
* Update to latest Rclone (v1.49.5)
+ **10/01/2019:**
* Update to latest Rclone (v1.49.4)
+ **09/23/2019:**
* Add environment variable SYNC_ONCE
+ **09/19/2019:**
* Add environment variable SYNC_OPTS_EVAL
+ **09/17/2019:**
* Update to latest Rclone (v1.49.3)
+ **09/10/2019:**
* Regression on log rotation
+ **09/09/2019:**
* Update to latest Rclone (v1.49.2)
+ **08/29/2019:**
* Update to latest Rclone (v1.49.1)
+ **08/20/2019:**
* Add start command for healthchecks.io calls
* Add debug messages for healthchecks.io calls
+ **08/19/2019:**
* Correct log rotation when there are no logs
+ **07/18/2019:**
* Optimizations to dockerfile
+ **06/22/2019:**
* Update to latest Rclone (v1.48.0)
+ **05/01/2019:**
* Initial release

<br />
<br />
<br />
<br />
Credit to Brian J. Cardiff for the orginal project @ https://github.com/bcardiff/docker-rclone
37 changes: 37 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

docker build --no-cache --build-arg RCLONE_VERSION=v1.47.0 -t pfidr/rclone:1.47 -t pfidr/rclone:1.47.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.48.0 -t pfidr/rclone:1.48 -t pfidr/rclone:1.48.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.0 -t pfidr/rclone:1.49.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.1 -t pfidr/rclone:1.49.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.2 -t pfidr/rclone:1.49.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.3 -t pfidr/rclone:1.49.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.4 -t pfidr/rclone:1.49.4 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.5 -t pfidr/rclone:1.49.5 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.0 -t pfidr/rclone:1.50.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.1 -t pfidr/rclone:1.50.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.2 -t pfidr/rclone:1.50.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.51.0 -t pfidr/rclone:1.51.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.0 -t pfidr/rclone:1.52.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.1 -t pfidr/rclone:1.52.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.2 -t pfidr/rclone:1.52.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.3 -t pfidr/rclone:1.52.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.0 -t pfidr/rclone:1.53.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.1 -t pfidr/rclone:1.53.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.2 -t pfidr/rclone:1.53.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.3 -t pfidr/rclone:1.53.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.4 -t pfidr/rclone:1.53.4 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.54.0 -t pfidr/rclone:1.54.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.54.1 -t pfidr/rclone:1.54.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.55.0 -t pfidr/rclone:1.55.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.55.1 -t pfidr/rclone:1.55.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.0 -t pfidr/rclone:1.56.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.1 -t pfidr/rclone:1.56.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.2 -t pfidr/rclone:1.56.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.57.0 -t pfidr/rclone:1.57.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.58.0 -t pfidr/rclone:1.58.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.59.0 -t pfidr/rclone:1.59.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.60.0 -t pfidr/rclone:1.60.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.61.0 -t pfidr/rclone:1.61.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.61.1 -t pfidr/rclone:1.61.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.63.0 -t pfidr/rclone:1.63.0 -t pfidr/rclone:latest -t pfidr/rclone:test -t rclone_test .
92 changes: 84 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,73 @@

set -e

# Announce version
echo "INFO: Running $(rclone --version | head -n 1)"

# Make sure sync/copy command is ok
if [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "SYNC" ] && [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "COPY" ] && [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "MOVE" ]
then
echo "WARNING: rclone command '$RCLONE_CMD' is not supported by this container, please use sync/copy/move. Stopping."
exit 1
fi

# Make sure dir command is ok
if [ "$(echo "$RCLONE_DIR_CMD" | tr '[:lower:]' '[:upper:]')" != "LS" ] && [ "$(echo "$RCLONE_DIR_CMD" | tr '[:lower:]' '[:upper:]')" != "LSF" ]
then
echo "WARNING: rclone directory command '$RCLONE_DIR_CMD' is not supported by this container, please use ls or lsf. Stopping."
exit 1
fi

# Make sure UID and GID are both supplied
if [ -z "$GID" -a ! -z "$UID" ] || [ -z "$UID" -a ! -z "$GID" ]
then
echo "WARNING: Must supply both UID and GID or neither. Stopping."
exit 1
fi

# Process UID and GID
if [ ! -z "$GID" ]
then

#Get group name or add it
GROUP=$(getent group "$GID" | cut -d: -f1)
if [ -z "$GROUP" ]
then
GROUP=rclone
addgroup --gid "$GID" "$GROUP"
fi

#get user or add it
USER=$(getent passwd "$UID" | cut -d: -f1)
if [ -z "$USER" ]
then
USER=rclone
adduser \
--disabled-password \
--gecos "" \
--no-create-home \
--ingroup "$GROUP" \
--uid "$UID" \
"$USER" >/dev/null
fi
else
USER=$(whoami)
fi

# Re-write cron shortcut
case "$(echo "$CRON" | tr '[:lower:]' '[:upper:]')" in
*@YEARLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 1 *" && CRONS="0 0 1 1 *";;
*@ANNUALLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 1 *" && CRONS="0 0 1 1 *";;
*@MONTHLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 * *" && CRONS="0 0 1 * * ";;
*@WEEKLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * 0" && CRONS="0 0 * * 0";;
*@DAILY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * *" && CRONS="0 0 * * *";;
*@MIDNIGHT* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * *" && CRONS="0 0 * * *";;
*@HOURLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 * * * *" && CRONS="0 * * * *";;
*@* ) echo "WARNING: Cron shortcut $CRON is not supported. Stopping." && exit 1;;
* ) CRONS=$CRON;;
esac

# Set time zone if passed in
if [ ! -z "$TZ" ]
then
cp /usr/share/zoneinfo/$TZ /etc/localtime
Expand All @@ -10,34 +77,44 @@ fi

rm -f /tmp/sync.pid

# Check for source and destination ; launch config if missing
if [ -z "$SYNC_SRC" ] || [ -z "$SYNC_DEST" ]
then
echo "INFO: No SYNC_SRC and SYNC_DEST found. Starting rclone config"
rclone config $RCLONE_OPTS
su "$USER" -c "rclone config $RCLONE_OPTS"
echo "INFO: Define SYNC_SRC and SYNC_DEST to start sync process."
else
# SYNC_SRC and SYNC_DEST setup
# run sync either once or in cron depending on CRON
if [ -z "$FAIL_URL" ]
then

#Create fail URL if CHECK_URL is populated but FAIL_URL is not
if [ ! -z "$CHECK_URL" ] && [ -z "$FAIL_URL" ]
then
FAIL_URL="${CHECK_URL}/fail"
fi
if [ -z "$CRON" ]

if [ -z "$CRONS" ]
then
echo "INFO: No CRON setting found. Running sync once."
echo "INFO: Add CRON=\"0 0 * * *\" to perform sync every midnight"
/sync.sh
su "$USER" -c /sync.sh
else
if [ -z "$FORCE_SYNC" ]
then
echo "INFO: Add FORCE_SYNC=1 to perform a sync upon boot"
else
/sync.sh
su "$USER" -c /sync.sh
fi

if [ ! -z "$SYNC_ONCE" ]
then
echo "INFO: SYNC_ONCE option activated. Stopping now."
exit 0
fi

# Setup cron schedule
crontab -d
echo "$CRON /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
echo "$CRONS su $USER -c /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
if [ -z "$CRON_ABORT" ]
then
echo "INFO: Add CRON_ABORT=\"0 6 * * *\" to cancel outstanding sync at 6am"
Expand All @@ -56,4 +133,3 @@ else
tail -F /tmp/crond.log /tmp/sync.log
fi
fi

Loading

0 comments on commit ba0367a

Please sign in to comment.