Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cron in docker image #172

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
!cmd
!internal
!go.*
!/*.sh
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ RUN go build
FROM alpine
RUN apk add --no-cache restic rclone bash openssh
COPY --from=builder /app/autorestic /usr/bin/autorestic
CMD [ "autorestic" ]
COPY entrypoint.sh /entrypoint.sh
COPY crond.sh /crond.sh
RUN chmod +x /entrypoint.sh /crond.sh
# show autorestic cron logs in docker
RUN ln -sf /proc/1/fd/1 /var/log/autorestic-cron.log
# run autorestic-cron every minute
RUN echo -e "*/1 * * * * bash /crond.sh" >> /etc/crontabs/root

CMD [ "/entrypoint.sh" ]
4 changes: 4 additions & 0 deletions crond.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "autorestic cron process has started"
autorestic -c $CRON_CONFIG_DIR --ci cron > /var/log/autorestic-cron.log 2>&1
echo "autorestic cron process has finished"
34 changes: 33 additions & 1 deletion docs/markdown/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ docker run --rm \\
autorestic backup -va -c /data/.autorestic.yaml
```

## Cron

To use cron with the docker image,
you have 2 environment variables.
`AUTORESTIC_INITIAL_ARGS` and `CRON_CONFIG_DIR`

- `AUTORESTIC_INITIAL_ARGS` is arguments used for the initial autorestic command on container start up, if you don't set it, autorestic would show available commands.

For example:
```
AUTORESTIC_INITIAL_ARGS=backup -va -c /.autorestic.yaml
```
Would mean `autorestic backup -va -c /.autorestic.yaml` on container startup.

- `CRON_CONFIG_DIR` to enable Cron, you need to set this to the in-contaier directory of the config file you want to use with Cron.

### Example

```
version: '3.3'

services:
autorestic:
image: cupcakearmy/autorestic:latest
environment:
- AUTORESTIC_INITIAL_ARGS=backup -va -c /.autorestic.yaml
- CRON_CONFIG_DIR=/.autorestic.yaml
volumes:
- ./autorestic.yaml:/.autorestic.yaml
```
This would run `autorestic backup -va -c /.autorestic.yaml` on container startup, and check for any backups due in /.autorestic.yaml.

## Rclone

For rclone you will have to also mount the rclone config file to `/root/.config/rclone/rclone.conf`.
Expand All @@ -25,4 +57,4 @@ To check where it is located you can run the following command: `rclone config f
docker run \\
-v /home/user/.config/rclone/rclone.conf:/root/.config/rclone/rclone.conf:ro \\
...
```
```
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
autorestic $AUTORESTIC_INITIAL_ARGS
if [ -n "$CRON_CONFIG_DIR" ]
then
echo "CRON_CONFIG_DIR is set, cron enabled"
crond -f -L /var/log/cron.log
fi