Docker image to perform a rclone sync based on a cron schedule, with healthchecks.io monitoring.
rclone is a command line program to sync files and directories to and from:
- Google Drive
- Amazon S3
- Openstack Swift / Rackspace cloud files / Memset Memstore
- Dropbox
- Google Cloud Storage
- Amazon Drive
- Microsoft OneDrive
- Hubic
- Backblaze B2
- Yandex Disk
- SFTP
- FTP
- HTTP
- The local filesystem
rclone needs a configuration file where credentials to access different storage provider are kept.
By default, this image uses a file /config/rclone.conf and a mounted volume may be used to keep that information persisted.
A first run of the container can help in the creation of the file, but feel free to manually create one.
$ mkdir config
$ docker run --rm -it -v $(pwd)/config:/config chbgdn/rclone
docker-compose
version: "3"
services:
rclone:
image: chbgdn/rclone:latest
restart: unless-stopped
volumes:
- $(pwd)/config:/config
- /directory/for/backup:/source
environment:
- "UID=1000"
- "GID=1000"
- "TZ=Europe/Kyiv"
- "RCLONE_CMD=sync" # sync/copy/move
- "SYNC_SRC=/source" # source directory path
- "SYNC_DEST=myremote:path/to/dir" # destination for rclone
- "CRON=0 0 * * *" # perform sync every midnight (supprorts cron shortcuts)
- "CRON_ABORT=0 6 * * *" # abort sync at 6am
- "FORCE_SYNC=1" # perform a sync upon boot
docker-cli
$ docker run --rm -it -v $(pwd)/config:/config -v /directory/for/backup:/source -e SYNC_SRC="/source" -e SYNC_DEST="myremote:path/to/dir" -e TZ="Europe/Kyiv" -e CRON="0 0 * * *" -e CRON_ABORT="0 6 * * *" -e FORCE_SYNC=1 chbgdn/rcloneA few environment variables allow you to customize the behavior of rclone:
SYNC_SRCsource location forrclone sync/copy/movecommand. Directories with spaces should be wrapped in single quotes.SYNC_DESTdestination location forrclone sync/copy/movecommand. Directories with spaces should be wrapped in single quotes.SYNC_OPTSadditional options forrclone sync/copy/movecommand. Defaults to-vSYNC_OPTS_EVALfurther additional options forrclone sync/copy/movecommand. 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_ONCEset variable to only run the sync one time and then exit the containerRCLONE_CMDset variable tosynccopyormovewhen running rclone. Defaults tosyncRCLONE_DIR_CMDset variable tolsorlsffor source directory check style. Defaults tolsRCLONE_DIR_CMD_DEPTHset the limit of the recursion depth to this. Defaults to-1(rclone default)RCLONE_DIR_CHECK_SKIPset variable to skip source directory check before sync. Use with cautionCRONcrontab schedule0 0 * * *to perform sync every midnight. Also supprorts cron shortcuts:@yearly@monthly@weekly@daily@hourlyCRON_ABORTcrontab schedule0 6 * * *to abort sync at 6amFORCE_SYNCset variable to perform a sync upon bootCHECK_URLhealthchecks.io url or similar cron monitoring to perform aGETafter a successful syncFAIL_URLFail URL to perform aGETafter unsuccessful execution. By default this isCHECK_URLwith appended "/fail" at the endHC_LOGset variable to send log data to healthchecks.io.OUTPUT_LOGmust also be set.OUTPUT_LOGset variable to output log file to /logsROTATE_LOGset variable to delete logs older than specified days from /logsTZset the timezone to use for the cron and logAmerica/ChicagoUIDset variable to specify user to run rclone as. Must also use GID.GIDset 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
See rclone sync docs for source/dest syntax and additional options.
Credit to pfidr