Skip to content

Commit

Permalink
docs: schedule inside a container using a non-root user (#348)
Browse files Browse the repository at this point in the history
* contrib: schedule inside a container with a non-root user

* moved contrib to documentation instead

* reword documentation
  • Loading branch information
creativeprojects authored Mar 23, 2024
1 parent 3b8613e commit 8297f50
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 231 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ status.json
/docs/static/jsonschema
/public
.hugo_build.lock

.env
25 changes: 25 additions & 0 deletions build/Dockerfile_non-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM alpine:latest

LABEL org.opencontainers.image.documentation="https://creativeprojects.github.io/resticprofile/"
LABEL org.opencontainers.image.source="https://github.com/creativeprojects/resticprofile"


ARG ARCH=amd64
ENV TZ=Etc/UTC

COPY build/restic-${ARCH} /usr/bin/restic
COPY build/rclone-${ARCH} /usr/bin/rclone
COPY resticprofile /usr/bin/resticprofile

RUN apk add --no-cache openssh-client-default curl tzdata ca-certificates supercronic && \
chmod +x /usr/bin/restic /usr/bin/rclone /usr/bin/resticprofile && \
adduser -D -h /resticprofile resticprofile && \
mkdir -p /resticprofile && \
touch /resticprofile/crontab && \
chown -R resticprofile:resticprofile /resticprofile

VOLUME /resticprofile
WORKDIR /resticprofile

ENTRYPOINT ["resticprofile"]
CMD ["--help"]
34 changes: 1 addition & 33 deletions contrib/ansible/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
# resticprofile deployment using ansible

This is very much work in progress. Once I get a stable ansible script I should publish it to Ansible Galaxy.

The playbook is installing (or upgrading):

* latest restic binary to `/usr/local/bin`
* latest resticprofile binary to `/usr/local/bin`
* the resticprofile configuration file from a template file found in `./resticprofile/{{ inventory_hostname }}/profiles.*` to `/root/resticprofile/profiles.*`
* password files that can be encrypted using ansible vault. These files are located in `./resticprofile/{{ inventory_hostname }}/keys/*`: they will be decrypted and saved to `/root/resticprofile/`.
* other files (like files needed for `--exclude-file`, `--files-from` or anything else you need) from `./resticprofile/{{ inventory_hostname }}/copy/*` to `/root/resticprofile/`

### Requirement

Each target machine must have one variable named `arch` containing the resticprofile OS & Arch. You can see a list of all the available OS & Arch couples on the [releases page](https://github.com/creativeprojects/resticprofile/releases).

Typically, a binary will be distributed using this convention:

`resticprofile-[VERSION]_[OS]_[ARCH].tar.gz`

Your host variables file should declare a `arch` variable containing the `[OS]_[ARCH]` part of the file name.

#### Examples:

```
arch: linux_amd64
```

or for a Raspberry pi 3+:

```
arch: linux_armv7
```

Note: _I might find a way to detect this automatically at some point_
Contribution moved to the documentation: https://creativeprojects.github.io/resticprofile/installation/ansible/
196 changes: 0 additions & 196 deletions contrib/ansible/resticprofile.yml

This file was deleted.

1 change: 0 additions & 1 deletion docs/content/contributions/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Please share your resticprofile recipes, fancy configuration files, or tips and

I have created a [contributions section](https://github.com/creativeprojects/resticprofile/tree/master/contrib) for that matter.

- [ansible playbook](https://github.com/creativeprojects/resticprofile/tree/master/contrib/ansible)
- [shell completion](https://github.com/creativeprojects/resticprofile/tree/master/contrib/completion)
- [export status to grafana](https://github.com/creativeprojects/resticprofile/tree/master/contrib/grafana)
- [send email on systemd timer error](https://github.com/creativeprojects/resticprofile/tree/master/contrib/systemd)
Expand Down
93 changes: 93 additions & 0 deletions docs/content/schedules/non-root-schedule-in-container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: "User schedule in container"
weight: 150
tags: ["v0.27.0"]
---


You can schedule your backups with resticprofile by running `crond` inside a container.

This configuration uses [supercronic](https://github.com/aptible/supercronic) to run scheduled backups as a non-root user.

You can create a container with this modified version from the [official image](https://github.com/creativeprojects/resticprofile/blob/master/build/Dockerfile):

```Dockerfile
FROM alpine:latest

LABEL org.opencontainers.image.documentation="https://creativeprojects.github.io/resticprofile/"
LABEL org.opencontainers.image.source="https://github.com/creativeprojects/resticprofile"


ARG ARCH=amd64
ENV TZ=Etc/UTC

COPY build/restic-${ARCH} /usr/bin/restic
COPY build/rclone-${ARCH} /usr/bin/rclone
COPY resticprofile /usr/bin/resticprofile

RUN apk add --no-cache openssh-client-default curl tzdata ca-certificates supercronic && \
chmod +x /usr/bin/restic /usr/bin/rclone /usr/bin/resticprofile && \
adduser -D -h /resticprofile resticprofile && \
mkdir -p /resticprofile && \
touch /resticprofile/crontab && \
chown -R resticprofile:resticprofile /resticprofile

VOLUME /resticprofile
WORKDIR /resticprofile

ENTRYPOINT ["resticprofile"]
CMD ["--help"]
```

Here's a `docker-compose` example loading configuration from a `.env` file:

```yaml
version: '2'

services:
scheduled-backup:
image: creativeprojects/resticprofile:${RP_VERSION:-latest}
container_name: backup_container
hostname: backup_container
user: resticprofile:resticprofile
entrypoint: '/bin/sh'
command:
- '-c'
- 'resticprofile schedule --all && supercronic /resticprofile/crontab'
volumes:
- '${RP_CONFIG}:/resticprofile/profiles.yaml:ro'
- '${RP_KEYFILE}:/resticprofile/key:ro'
- '${BACKUP_SOURCE}:/source:ro'
- '${RP_REPOSITORY}:/restic_repo'
environment:
- TZ=${TIMEZONE:-Etc/UTC}

```

with the corresponding resticprofile configuration running a backup every 15 minutes:

```yaml

global:
scheduler: crontab:-:/resticprofile/crontab

default:
password-file: key
repository: "local:/restic_repo"
initialize: true
backup:
source: /source
exclude-caches: true
one-file-system: true
schedule: "*:00,05,10,15,20,25,30,35,40,45,50,55"
schedule-permission: user
check-before: true

```

## More information

[Discussion on Supercronic](https://github.com/creativeprojects/resticprofile/issues/288)

[Discussion on non-root container](https://github.com/creativeprojects/resticprofile/issues/321)

2 changes: 1 addition & 1 deletion docs/themes/hugo-theme-relearn
Submodule hugo-theme-relearn updated 65 files
+1 −0 .github/FUNDING.yml
+1 −1 .github/actions/release_milestone/action.yaml
+1 −1 .github/workflows/docs-build-deployment.yaml
+1 −1 .github/workflows/docs-build.yaml
+1 −1 .github/workflows/version-release.yaml
+2 −2 archetypes/chapter.md
+1 −2 archetypes/default.md
+1 −1 archetypes/home.md
+12 −12 exampleSite/config/_default/hugo.toml
+2 −0 exampleSite/config/_default/params.toml
+1 −1 exampleSite/content/_index.en.md
+44 −0 exampleSite/content/basics/CHANGELOG.md
+16 −17 exampleSite/content/basics/branding/_index.en.md
+12 −1 exampleSite/content/basics/configuration/_index.en.md
+37 −29 exampleSite/content/basics/customization/_index.en.md
+64 −41 exampleSite/content/basics/installation/_index.en.md
+33 −20 exampleSite/content/basics/migration/_index.en.md
+2 −2 exampleSite/content/basics/topbar/_index.en.md
+19 −22 exampleSite/content/cont/archetypes/_index.en.md
+19 −277 exampleSite/content/cont/frontmatter/_index.en.md
+262 −0 exampleSite/content/cont/frontmatter/frontmatter.toml
+10 −13 exampleSite/content/cont/i18n/_index.en.md
+22 −15 exampleSite/content/cont/imageeffects.en.md
+35 −35 exampleSite/content/cont/markdown.en.md
+29 −30 exampleSite/content/cont/menushortcuts.en.md
+2 −2 exampleSite/content/cont/pages/index.en.md
+8 −10 exampleSite/content/cont/taxonomy.en.md
+3 −3 exampleSite/content/dev/screenshots/_index.en.md
+7 −22 exampleSite/content/shortcodes/highlight.en.md
+4 −6 exampleSite/content/shortcodes/math.en.md
+43 −7 exampleSite/content/shortcodes/mermaid.en.md
+1,131 −98 exampleSite/content/shortcodes/openapi/petstore.json
+1,548 −0 exampleSite/content/shortcodes/openapi/petstore.yaml
+9 −9 exampleSite/content/shortcodes/siteparam.en.md
+74 −0 exampleSite/layouts/partials/shortcodes/multiconfig.html
+10 −0 exampleSite/layouts/shortcodes/multiconfig.html
+1 −1 layouts/404.html
+4 −3 layouts/_default/_markup/render-codeblock-math.html
+4 −3 layouts/_default/_markup/render-codeblock-mermaid.html
+1 −0 layouts/_default/_markup/render-image.html
+2 −2 layouts/partials/content-footer.html
+11 −7 layouts/partials/dependencies/openapi.html
+1 −1 layouts/partials/header.html
+10 −10 layouts/partials/menu.html
+11 −0 layouts/partials/relBasePath.hugo
+10 −0 layouts/partials/relBaseUri.hugo
+2 −2 layouts/partials/shortcodes/expand.html
+33 −20 layouts/partials/shortcodes/highlight.html
+29 −5 layouts/partials/shortcodes/image.html
+5 −3 layouts/partials/shortcodes/link.html
+22 −3 layouts/partials/shortcodes/math.html
+24 −3 layouts/partials/shortcodes/mermaid.html
+7 −4 layouts/partials/shortcodes/openapi.html
+4 −6 layouts/partials/stylesheet.html
+1 −1 layouts/partials/version.txt
+2 −1 static/css/theme-neon.css
+16 −15 static/css/theme.css
+1 −0 static/css/variant-internal.css
+701 −318 static/js/mermaid.min.js
+2 −2 static/js/search.js
+1 −1 static/js/swagger-ui/swagger-ui-bundle.js
+1 −1 static/js/swagger-ui/swagger-ui-standalone-preset.js
+1 −1 static/js/swagger-ui/swagger-ui.css
+94 −51 static/js/theme.js
+13 −13 static/js/variant.js

0 comments on commit 8297f50

Please sign in to comment.