├── .cz.yaml
├── .github
└── workflows
│ └── repo-lockdown.yml
├── .gitignore
├── .gitlab-ci.yml
├── .gitlab
├── build-and-release.sh
├── issue_templates
│ ├── Default.md
│ └── Feature_Request.md
└── prepare-release.sh
├── .pre-commit-config.yaml
├── .releaserc.json
├── .shellcheckrc
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── docker-compose.dev.yml
├── docker-compose.yml
└── src
├── app
└── backup.sh
├── opt
└── scripts
│ ├── helper.sh
│ ├── logging.sh
│ └── set-env.sh
└── usr
└── local
└── bin
├── entrypoint.sh
└── healthcheck.sh
/.cz.yaml:
--------------------------------------------------------------------------------
1 | commitizen:
2 | name: cz_conventional_commits
3 | version_scheme: semver
4 |
--------------------------------------------------------------------------------
/.github/workflows/repo-lockdown.yml:
--------------------------------------------------------------------------------
1 | name: 'Lock down repository'
2 |
3 | on:
4 | issues:
5 | types: opened
6 | pull_request:
7 | types: opened
8 |
9 | jobs:
10 | action:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: dessant/repo-lockdown@v4
14 | with:
15 | issue-labels: 'off-topic'
16 | issue-comment: >
17 | Thanks for your contribution!
18 |
19 | However, this repository does not accept bug reports,
20 | since this is only a mirror of
21 | https://gitlab.com/1O/vaultwarden-backup.
22 |
23 | Please feel free to open the issue there.
24 | skip-closed-issue-comment: true
25 | pr-comment: >
26 | Thanks for your contribution!
27 |
28 | However, this repository does not accept pull requests,
29 | since this is only a mirror of
30 | https://gitlab.com/1O/vaultwarden-backup.
31 |
32 | Please feel free to open the pull request there.
33 | skip-closed-pr-comment: true
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | test/
2 | .env
3 | vw-data/
4 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | stages:
2 | - push:readme
3 | - build-and-release
4 |
5 | variables:
6 | DOCKERHUB_REGISTRY: docker.io
7 | DOCKERHUB_REPO: vaultwarden-backup
8 | IMAGE_NAME_DOCKERHUB: $DOCKERHUB_REGISTRY/$DOCKERHUB_USER/$DOCKERHUB_REPO
9 | # see https://gitlab.com/gitlab-org/gitlab-runner/issues/4501 and https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled-in-kubernetes
10 | # the variables following DOCKER_HOST are needed because we use alpine as build image and not docker. We do this to integrate semantic-release bot
11 | DOCKER_DRIVER: overlay2
12 | DOCKER_TLS_CERTDIR: "/certs"
13 | DOCKER_HOST: tcp://docker:2376
14 | DOCKER_TLS_VERIFY: 1
15 | DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
16 | # See https://github.com/docker/buildx/releases
17 | BUILDX_VERSION: v0.9.1
18 | BUILDX_ARCH: linux-amd64
19 |
20 | workflow:
21 | rules:
22 | - if: $CI_PIPELINE_SOURCE == "merge_request_event"
23 | - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
24 | when: never
25 | - if: $CI_COMMIT_BRANCH
26 |
27 | .docker_login: &docker_login
28 | docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
29 |
30 | .dockerhub_login: &dockerhub_login
31 | docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_PASSWORD" $DOCKERHUB_REGISTRY
32 |
33 | .docker_build_template: &docker_build
34 | image: node:lts-alpine
35 | stage: build-and-release
36 | services:
37 | - name: docker:dind
38 | command: ["--experimental"]
39 | before_script:
40 | - apk add git zip docker curl
41 | - docker info
42 | - mkdir -p ~/.docker/cli-plugins
43 | - curl -sSLo ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.$BUILDX_ARCH
44 | - chmod +x ~/.docker/cli-plugins/docker-buildx
45 | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
46 | - docker context create my-context
47 | - docker buildx create --use my-context
48 | - docker info
49 | - npm install -g semantic-release @semantic-release/gitlab @semantic-release/git @semantic-release/exec @semantic-release/changelog
50 |
51 | pre-commit:
52 | stage: .pre
53 | image: python:3.11
54 | script:
55 | - pip install pre-commit
56 | - pre-commit run --all-files
57 | - pre-commit run --all-files --hook-stage manual commitizen-branch
58 | rules:
59 | - if: $CI_COMMIT_BRANCH != "main"
60 |
61 | build and release:main:
62 | <<: *docker_build
63 | script:
64 | - semantic-release
65 | - .gitlab/prepare-release.sh latest@$(date -Iseconds) # Also build latest version if there is no new release
66 | - .gitlab/build-and-release.sh latest
67 | rules:
68 | - if: $CI_COMMIT_BRANCH == "main"
69 |
70 | build and release:non-main:
71 | <<: *docker_build
72 | script:
73 | - .gitlab/prepare-release.sh 0.0.0-$CI_COMMIT_REF_SLUG
74 | - .gitlab/build-and-release.sh $CI_COMMIT_REF_SLUG
75 | rules:
76 | - if: $CI_COMMIT_BRANCH != "main"
77 |
--------------------------------------------------------------------------------
/.gitlab/build-and-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #set -xe
4 |
5 | ### Functions
6 |
7 | build() {
8 | docker buildx build \
9 | --push \
10 | --platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
11 | "$@" .
12 | }
13 |
14 | if [ $# -ne 1 ]; then exit 1; fi
15 |
16 | TAG="$1"
17 |
18 | # Gitlab tag
19 | docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
20 | set -- --tag "$CI_REGISTRY_IMAGE:$TAG"
21 |
22 | # Docker hub tag
23 | if [ -n "$CI_REGISTRY_USER" ] && [ -n "$DOCKERHUB_PASSWORD" ] && [ -n "$DOCKERHUB_REGISTRY" ]&& [ -n "$DOCKERHUB_USER" ]&& [ -n "$DOCKERHUB_REPO" ]; then
24 | docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_PASSWORD" "$DOCKERHUB_REGISTRY"
25 | set -- "$@" --tag "$DOCKERHUB_USER/$DOCKERHUB_REPO:$TAG"
26 | # Used to update deprecated image
27 | set -- "$@" --tag "$DOCKERHUB_USER/bw_backup:$TAG"
28 | fi
29 |
30 | build "$@"
31 |
--------------------------------------------------------------------------------
/.gitlab/issue_templates/Default.md:
--------------------------------------------------------------------------------
1 | ## Summary
2 |
3 |
4 | ---
5 |
6 | ## Expected Behavior
7 |
8 |
9 | ---
10 |
11 | ## Current Behavior
12 |
13 |
14 | ---
15 |
16 | ## Possible Solution
17 |
18 |
19 | ---
20 |
21 | ## Steps to reproduce
22 |
23 | 1.
24 | 1.
25 | 1.
26 | 1.
27 |
28 | ---
29 |
30 | ## Settings (Environment)
31 |
32 |
33 | ---
34 |
35 | ## Relevant logs and/or screenshots
36 |
37 |
--------------------------------------------------------------------------------
/.gitlab/issue_templates/Feature_Request.md:
--------------------------------------------------------------------------------
1 | ## Short Summary
2 |
3 |
4 | ---
5 |
6 | ## Use case
7 |
8 |
--------------------------------------------------------------------------------
/.gitlab/prepare-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #set -xe
4 |
5 | if [ $# -ne 1 ]; then exit 1; fi
6 |
7 | NEW_VERSION=$1
8 |
9 | sed -Ei "s/(^export VW_BACKUP_VERSION=).*/\1${NEW_VERSION}/" src/opt/scripts/set-env.sh
10 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v4.5.0
4 | hooks:
5 | - id: check-added-large-files
6 | - id: check-shebang-scripts-are-executable
7 | - id: check-yaml
8 | - id: end-of-file-fixer
9 | - id: mixed-line-ending
10 | args:
11 | - --fix=lf
12 | - id: trailing-whitespace
13 |
14 | - repo: https://github.com/commitizen-tools/commitizen
15 | rev: v3.13.0
16 | hooks:
17 | - id: commitizen
18 | - id: commitizen-branch
19 | stages:
20 | - manual
21 | args:
22 | - --rev-range
23 | - origin/main..HEAD
24 |
--------------------------------------------------------------------------------
/.releaserc.json:
--------------------------------------------------------------------------------
1 | {
2 | "branches": [
3 | "main"
4 | ],
5 | "plugins": [
6 | "@semantic-release/commit-analyzer",
7 | "@semantic-release/release-notes-generator",
8 | [
9 | "@semantic-release/exec",
10 | {
11 | "prepareCmd": ".gitlab/prepare-release.sh ${nextRelease.version}",
12 | "successCmd": ".gitlab/build-and-release.sh ${nextRelease.version}"
13 | }
14 | ],
15 | "@semantic-release/changelog",
16 | {
17 | "changelogFile": "CHANGELOG.md"
18 | },
19 | "@semantic-release/git",
20 | {
21 | "assets": [
22 | "CHANGELOG.md"
23 | ]
24 | },
25 | "@semantic-release/gitlab"
26 | ],
27 | "preset": "angular"
28 | }
29 |
--------------------------------------------------------------------------------
/.shellcheckrc:
--------------------------------------------------------------------------------
1 | external-sources=true
2 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # [2.1.0](https://gitlab.com/1O/vaultwarden-backup/compare/v2.0.4...v2.1.0) (2025-01-12)
2 |
3 |
4 | ### Features
5 |
6 | * Added feature to skip backups if there are no changes ([3923862](https://gitlab.com/1O/vaultwarden-backup/commit/3923862bc41b5e85f58ebaa608c56568ad890367)), closes [#34](https://gitlab.com/1O/vaultwarden-backup/issues/34)
7 |
8 | ## [2.0.4](https://gitlab.com/1O/vaultwarden-backup/compare/v2.0.3...v2.0.4) (2023-07-04)
9 |
10 |
11 | ### Bug Fixes
12 |
13 | * Do not use live database file in backup ([229b586](https://gitlab.com/1O/vaultwarden-backup/commit/229b5869ef14afc42df89ccd22c96fe75846a69d)), closes [#31](https://gitlab.com/1O/vaultwarden-backup/issues/31)
14 | * fixed broken gpg backup and wrong db ([3df0614](https://gitlab.com/1O/vaultwarden-backup/commit/3df0614d66c6bed1c063c04af6b4a39a5f398cc1)), closes [#31](https://gitlab.com/1O/vaultwarden-backup/issues/31) [#33](https://gitlab.com/1O/vaultwarden-backup/issues/33)
15 | * fixed cronjob ([9fc2ee6](https://gitlab.com/1O/vaultwarden-backup/commit/9fc2ee6f1e6cb845ccf5b3897bc562b4987d335e)), closes [#32](https://gitlab.com/1O/vaultwarden-backup/issues/32)
16 | * re-initiate cron on change ([3e1b71c](https://gitlab.com/1O/vaultwarden-backup/commit/3e1b71ccbf436216deb3b075910d933680d67370))
17 |
18 | ## [2.0.3](https://gitlab.com/1O/vaultwarden-backup/compare/v2.0.2...v2.0.3) (2023-07-01)
19 |
20 |
21 | ### Bug Fixes
22 |
23 | * fixed cronjob ([a2aaccb](https://gitlab.com/1O/vaultwarden-backup/commit/a2aaccb78664adbb6ac2df9481c58f0b74b9ee5c)), closes [#32](https://gitlab.com/1O/vaultwarden-backup/issues/32)
24 |
25 | ## [2.0.2](https://gitlab.com/1O/vaultwarden-backup/compare/v2.0.1...v2.0.2) (2023-07-01)
26 |
27 |
28 | ### Bug Fixes
29 |
30 | * re-initiate cron on change ([eb37e56](https://gitlab.com/1O/vaultwarden-backup/commit/eb37e563505b11f25d4f5289f8f8a4093a5a1cf9))
31 |
32 | ## [2.0.1](https://gitlab.com/1O/vaultwarden-backup/compare/v2.0.0...v2.0.1) (2023-06-02)
33 |
34 |
35 | ### Bug Fixes
36 |
37 | * version number in latest builds was incorrect ([5c55d02](https://gitlab.com/1O/vaultwarden-backup/commit/5c55d0292fee0a569d43b96b9500e5a8437ea483)), closes [#30](https://gitlab.com/1O/vaultwarden-backup/issues/30)
38 |
39 | # [2.0.0](https://gitlab.com/1O/vaultwarden-backup/compare/v1.1.0...v2.0.0) (2023-04-07)
40 |
41 |
42 | * Merge branch 'dev' into 'main' ([7a98065](https://gitlab.com/1O/vaultwarden-backup/commit/7a9806595c81aacf4d4c838601fca196317155c5))
43 |
44 |
45 | ### Features
46 |
47 | * Added BACKUP_ON_STARTUP ([4952ce3](https://gitlab.com/1O/vaultwarden-backup/commit/4952ce3c963d6f287c76decadc6c93133821c34d))
48 | * Password protection and switch to xz ([fb4b207](https://gitlab.com/1O/vaultwarden-backup/commit/fb4b207f23f8b311ebe3230eee352069ebe75de2)), closes [#28](https://gitlab.com/1O/vaultwarden-backup/issues/28)
49 |
50 |
51 | ### BREAKING CHANGES
52 |
53 | * Include database backup in tar
54 |
55 | See merge request 1O/vaultwarden-backup!13
56 |
57 | # [1.1.0](https://gitlab.com/1O/vaultwarden-backup/compare/v1.0.4...v1.1.0) (2023-01-02)
58 |
59 |
60 | ### Bug Fixes
61 |
62 | * Added error counter to critical errors ([0f53b1d](https://gitlab.com/1O/vaultwarden-backup/commit/0f53b1d31b841d9d932fcc860399c211ff44684e))
63 | * init health file ([a327c8e](https://gitlab.com/1O/vaultwarden-backup/commit/a327c8e5506a39b5f688d449eb3ddc987c6822df))
64 |
65 |
66 | ### Features
67 |
68 | * added container health check ([c3364dd](https://gitlab.com/1O/vaultwarden-backup/commit/c3364dda22a0ab7117a2bc77d519435668d45880))
69 |
70 | ## [1.0.4](https://gitlab.com/1O/vaultwarden-backup/compare/v1.0.3...v1.0.4) (2022-04-19)
71 |
72 |
73 | ### Bug Fixes
74 |
75 | * Make set-env.sh executable ([6f403c8](https://gitlab.com/1O/vaultwarden-backup/commit/6f403c862e2cadf16059a28587d1c75aa08b761b)), closes [#24](https://gitlab.com/1O/vaultwarden-backup/issues/24)
76 |
77 | ## [1.0.3](https://gitlab.com/1O/vaultwarden-backup/compare/v1.0.2...v1.0.3) (2022-02-04)
78 |
79 |
80 | ### Bug Fixes
81 |
82 | * deprecation check for $LOGFILE ([11d6cf9](https://gitlab.com/1O/vaultwarden-backup/commit/11d6cf93b0e5b2ea1de84932b84aacd83e40f0c4))
83 | * Moved deprecation checks to set-env script ([81f6190](https://gitlab.com/1O/vaultwarden-backup/commit/81f619001e1028ea6aad372237c22bb43bded045)), closes [#23](https://gitlab.com/1O/vaultwarden-backup/issues/23)
84 | * Set LOG_LEVEL first ([d5ee0b1](https://gitlab.com/1O/vaultwarden-backup/commit/d5ee0b1c60ba5d3c8aab57a6abffbf70f968a72d)), closes [#23](https://gitlab.com/1O/vaultwarden-backup/issues/23)
85 |
86 | ## [1.0.2](https://gitlab.com/1O/vaultwarden-backup/compare/v1.0.1...v1.0.2) (2022-01-31)
87 |
88 |
89 | ### Bug Fixes
90 |
91 | * always create logfiles as $UID:$GID ([0034bfb](https://gitlab.com/1O/vaultwarden-backup/commit/0034bfb70107daf3a70039320ac18a57a85d55f6)), closes [#21](https://gitlab.com/1O/vaultwarden-backup/issues/21)
92 | * Fixed permissions issues with log files ([fec55cc](https://gitlab.com/1O/vaultwarden-backup/commit/fec55cce32790cc23909922f1b1f6ef88dd87b9c)), closes [#21](https://gitlab.com/1O/vaultwarden-backup/issues/21)
93 |
94 | ## [1.0.1](https://gitlab.com/1O/vaultwarden-backup/compare/v1.0.0...v1.0.1) (2022-01-29)
95 |
96 |
97 | ### Bug Fixes
98 |
99 | * Fixed DELETE_AFTER ([b945105](https://gitlab.com/1O/vaultwarden-backup/commit/b945105fd620a07b6a7f513cad9c250e52afab08))
100 | * Fixed permission issues ([6108810](https://gitlab.com/1O/vaultwarden-backup/commit/610881056f6ed89bf6cf30b645121f9edd5ddfb5)), closes [#19](https://gitlab.com/1O/vaultwarden-backup/issues/19) [#20](https://gitlab.com/1O/vaultwarden-backup/issues/20) [#21](https://gitlab.com/1O/vaultwarden-backup/issues/21)
101 | * Fixed su-exec issues in manual mode ([62f9db9](https://gitlab.com/1O/vaultwarden-backup/commit/62f9db996236e649ce07144d056dfae2e2a59dbf)), closes [#20](https://gitlab.com/1O/vaultwarden-backup/issues/20)
102 | * loop when run with UID zero ([724dd65](https://gitlab.com/1O/vaultwarden-backup/commit/724dd657ccb41caec2b0a298c19a28be3caa21dd))
103 |
104 | # [1.0.0](https://gitlab.com/1O/vaultwarden-backup/compare/v0.0.8...v1.0.0) (2022-01-26)
105 |
106 |
107 | ### Features
108 |
109 | * renamed to vaultwarden-backup ([4ce504e](https://gitlab.com/1O/vaultwarden-backup/commit/4ce504e6debb6cd3993a9f36135b6db539f01dd5)), closes [#18](https://gitlab.com/1O/vaultwarden-backup/issues/18)
110 |
111 |
112 | ### BREAKING CHANGES
113 |
114 | * Changed environment variables
115 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Vaultwarden Backup
2 |
3 | Welcome to Vaultwarden Backup! We appreciate your interest in contributing to the project.
4 |
5 | All types of contributions are encouraged and valued. Please make sure to read this document before making your contribution.
6 |
7 | ---
8 |
9 | ## How to Contribute
10 |
11 | This project uses [semantic-release](https://github.com/semantic-release/semantic-release) to create new releases. This heavily relies on following the [Conventional Commits](https://www.conventionalcommits.org/) specification. So please ensure that all your commits are following the specification. There is an automated check included in the CI/CD pipeline which may cause the pipeline to fail if you try to submit a commit without a valid prefix.
12 |
13 | The general flow is pretty easy:
14 |
15 | 1. Before creating a merge request you should open a new [issue](https://gitlab.com/1O/vaultwarden-backup/-/issues/new) describing the bug you have or the feature you want to implement.
16 | 2. Fork the repository.
17 | 3. Create a new branch from the [dev](https://gitlab.com/1O/vaultwarden-backup/-/tree/dev) branch: git checkout -b my-feature-branch.
18 | 4. Make your changes and commit them using the semantic commit message format.
19 | 5. Push your changes to your forked repository: git push origin my-feature-branch.
20 | 6. Submit a merge request to the [dev](https://gitlab.com/1O/vaultwarden-backup/-/tree/dev) branch of this repository.
21 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | ARG ARCH=
2 | FROM ${ARCH}alpine:latest
3 |
4 | RUN apk add --no-cache \
5 | sqlite \
6 | busybox-suid \
7 | su-exec \
8 | tzdata \
9 | xz \
10 | gpg \
11 | gpg-agent
12 |
13 | COPY src /
14 |
15 | HEALTHCHECK CMD [ "healthcheck.sh" ]
16 |
17 | ENTRYPOINT ["entrypoint.sh"]
18 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 | Vaultwarden Backup
633 | Copyright (C) 2023 1O
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ### Vars ###
2 | CURRENT_DIR= $(shell pwd)
3 | BUILDX_VERSION = v0.7.1
4 | BUILDX_ARCH = linux-amd64
5 |
6 | ### Targets ###
7 | test-shellcheck:
8 | docker run --rm -v $(CURRENT_DIR)/src:/src --workdir /src --env-file .env koalaman/shellcheck-alpine sh -c 'shellcheck /src/usr/local/bin/*.sh /src/opt/scripts/*.sh /src/app/*.sh'
9 | test-release:
10 | docker run --rm -v $(CURRENT_DIR):/app --workdir /app --env-file .env node:lts-alpine sh -c '\
11 | apk add git && \
12 | npm install -g semantic-release conventional-changelog-conventionalcommits @semantic-release/changelog @semantic-release/git @semantic-release/gitlab && \
13 | semantic-release -d --dry-run --no-ci -r https://gitlab.com/1O/vaultwarden-backup'
14 | test-build:
15 | docker network create build-network 2>&1 | true
16 | docker run -d --rm --privileged --name dind \
17 | --network build-network --network-alias docker \
18 | -e DOCKER_TLS_CERTDIR=/certs \
19 | -v $(CURRENT_DIR)/test/build-certs:/certs \
20 | -v $(CURRENT_DIR)/test/build-certs:/certs/client \
21 | docker:dind --experimental 2>&1 | true
22 | docker run --rm --privileged --name builder \
23 | --network build-network \
24 | -e DOCKER_TLS_CERTDIR=/certs \
25 | -v $(CURRENT_DIR)/test/build-certs:/certs/client \
26 | -v $(CURRENT_DIR)/test/builds:/builds \
27 | -v $(CURRENT_DIR):/app --workdir /app \
28 | docker:latest sh -c '\
29 | apk add curl \
30 | && mkdir -p ~/.docker/cli-plugins \
31 | && curl -sSLo ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/$(BUILDX_VERSION)/buildx-$(BUILDX_VERSION).$(BUILDX_ARCH) \
32 | && chmod +x ~/.docker/cli-plugins/docker-buildx \
33 | && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes \
34 | && docker context create my-context \
35 | && docker buildx create --use my-context \
36 | && docker info \
37 | && docker buildx build --progress plain --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag vaultwarden-backup -o /builds .'
38 | docker stop dind
39 | docker network rm build-network
40 | build:
41 | docker build -t bruceforce/vaultwarden-backup $(CURRENT_DIR)
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vaultwarden Backup
2 |
3 | A simple cron powered backup image for [vaultwarden](https://github.com/dani-garcia/vaultwarden).
4 |
5 | :warning: Since Bitwarden_RS has been [renamed](https://github.com/dani-garcia/vaultwarden/discussions/1642#discussion-3344543) to Vaultwarden I also renamend this project to vaultwarden-backup. I will continue pushing the Image also to the old Docker repository for convenience. However you should also switch to the new Docker repository if you find some time. To do so just replace the `bruceforce/bw_backup` image by `bruceforce/vaultwarden-backup`.
6 |
7 | ## Why vaultwarden-backup?
8 |
9 | You might ask yourself "Why should I use a container for backing up my vaultwarden files if I can just include them in my regular backup?". One caveat of using regular backup software for databases is, that you shoud always stop your database server before you make a backup or you will risk data loss. To prevent this a proper backup command for your database should be used.
10 |
11 | Of course you could just create a cron job on your host with something like `sqlite3 "$VW_DATABASE_URL" ".backup '$BACKUP_FILE_DB'"` and back up the additional files and folders (like the attachments folder), using your preferred backup solution.
12 |
13 | However on some systems you are not able to add cronjobs by yourself, for example common NAS vendors don't allow this. That's why this image exists. Additionally it also includes the most important files and puts them in a `tar.xz` archive from where on your regular backup software could handle this files.
14 |
15 | ## Which files are included in the backup?
16 |
17 | By default all files that are recommended to backup by the official Vaultwarden wiki are backed up per default. You can modify this behavior with environment variables.
18 |
19 | ## Usage
20 |
21 | Since version v0.0.7 you can always use the `latest` tag, since the image is build with
22 | multi-arch support. Of course you can always use the version tags `vx.y.z` to stick
23 | to a specific version. Note however that there will be no security updates for the
24 | alpine base image if you stick to a version.
25 |
26 | Make sure that your **vaultwarden container is named `vaultwarden`** otherwise
27 | you have to replace the container name in the `--volumes-from` section of the `docker run` call.
28 |
29 | ### Automatic Backups
30 |
31 | A cron daemon is running inside the container and the container keeps running in background.
32 |
33 | The easiest way to use this is by adjusting the [docker-compose.yml](docker-compose.yml) to your needs. Below you find some example commands using `docker run`
34 |
35 | Start backup container with default settings (automatic backup at 5 am)
36 | ```sh
37 | docker run -d --restart=always --name vaultwarden-backup --volumes-from=vaultwarden bruceforce/vaultwarden-backup
38 | ```
39 |
40 | Example for hourly backups
41 | ```sh
42 | docker run -d --restart=always --name vaultwarden-backup --volumes-from=vaultwarden -e CRON_TIME="0 * * * *" bruceforce/vaultwarden-backup
43 | ```
44 |
45 | Example for backups that delete after 30 days
46 | ```sh
47 | docker run -d --restart=always --name vaultwarden-backup --volumes-from=vaultwarden -e TIMESTAMP=true -e DELETE_AFTER=30 bruceforce/vaultwarden-backup
48 | ```
49 |
50 | ### Manual Backups
51 |
52 | You can use the crontab of your host to schedule the backup and the container will only be running during the backup process.
53 |
54 | ```sh
55 | docker run --rm --volumes-from=vaultwarden bruceforce/vaultwarden-backup manual
56 | ```
57 |
58 | If you want the backed up file to be stored outside the container you have to mount
59 | a directory by adding `-v :`. The complete command could look like this
60 |
61 | ```sh
62 | docker run --rm --volumes-from=vaultwarden -e UID=0 -e BACKUP_DIR=/myBackup -e TIMESTAMP=true -v $(pwd)/myBackup:/myBackup bruceforce/vaultwarden-backup manual
63 | ```
64 |
65 | Keep in mind that the commands will be executed *inside* the container. So `$BACKUP_DIR` can be any place inside the container. Easiest would be to set it to `/data/backup` which will create the backup next to the original database file.
66 |
67 | ### Encryption/Decryption
68 |
69 | The backup tar.xz archive can be optionally encrypted. This can be useful if you keep sensitive attachments like ssh-keys in your vault and save the backup in an untrusted location.
70 |
71 | Since we use the tar command, because its most common on Linux systems and tar offers no encryption flag on its own, gpg is used to encrypt the tar.xz archive.
72 | There are two different ways to enable encryption of the backup: symmetric and asymmetric. You can only choose one of these two. If you set environment variables for both only asymmetric encryption will be performed.
73 |
74 | #### Encryption via passphrase (symmetric)
75 |
76 | The easiest way to encrypt the backup is by using symmetric encryption with a passphrase. This can be done by setting `ENCRYPTION_PASSWORD=` in the environment variables.
77 | However in some uses cases it might not be useful to store a passphrase as environment variable. In this cases you can encrypt the backup with your gpg public key.
78 |
79 | #### Encryption via gpg public key (asymmetric)
80 |
81 | Another way to encrypt the backup is by using a gpg public key. The public key needs to be provided as base64 string without line breaks. On most systems this can be achieved by `base64 -w 0 PathToYourPublicKey.asc`. After that set the environment variable `ENCRYPTION_BASE64_GPG_KEY` to your base64 encoded gpg public key.
82 |
83 | #### Decryption
84 |
85 | To decrypt the file you need to run `gpg --decrypt backup.tar.xz.gpg > backup.tar.xz`. This works for both encryption options. If you use gpg public key for encryption you must import your gpg keypair to your local keychain before this command works. For symmetric encryption this command just asks for your passphrase.
86 |
87 | ### Restore
88 |
89 | There is no automated restore process to prevent accidential data loss. So if you need to restore a backup you need to do this manually by following the steps below (assuming your backups are located at `./backup/` and your vaultwarden data ist located at `/var/lib/docker/volumes/vaultwarden/_data/`)
90 |
91 | ```sh
92 | # Delete any existing sqlite3 files
93 | rm /var/lib/docker/volumes/vaultwarden/_data/db.sqlite3*
94 |
95 | # Extract the archive
96 | # You may need to install xz first
97 | tar -xJvf ./backup/data.tar.xz -C /var/lib/docker/volumes/vaultwarden/_data/
98 | ```
99 |
100 | ## Environment variables
101 |
102 | For default values see [src/opt/scripts/set-env.sh](src/opt/scripts/set-env.sh)
103 |
104 | | ENV | Description |
105 | | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
106 | | APP_DIR | App dir inside the container (should not be changed) |
107 | | APP_DIR_PERMISSIONS | Permissions of app dir inside container (should not be changed) |
108 | | BACKUP_ADD_DATABASE [^3] | Set to `true` to include the database itself in the backup |
109 | | BACKUP_ADD_ATTACHMENTS [^3] | Set to `true` to include the attachments folder in the backup |
110 | | BACKUP_ADD_CONFIG_JSON [^3] | Set to `true` to include `config.json` in the backup |
111 | | BACKUP_ADD_ICON_CACHE [^3] | Set to `true` to include the icon cache folder in the backup |
112 | | BACKUP_ADD_RSA_KEY [^3] | Set to `true` to include the RSA keys in the backup |
113 | | BACKUP_ADD_SENDS [^3] | Set to `true` to include the sends folder in the backup |
114 | | BACKUP_USE_DEDUPE | Set to `true` to only create new backups if there were changes ([read the FAQ before using this](#i-have-deduplication-enabled-but-backups-are-created-even-if-there-were-no-changes)) |
115 | | BACKUP_HASHING_ALGORITHM | Hashing algorithm to use |
116 | | BACKUP_DIR | Seths the path of the backup folder *inside* the container |
117 | | BACKUP_DIR_PERMISSIONS | Sets the permissions of the backup folder (**CAUTION** [^1]). Set to -1 to disable. |
118 | | BACKUP_ON_STARTUP | Creates a backup right after container startup |
119 | | CRONFILE | Path to the cron file *inside* the container |
120 | | CRON_TIME | Cronjob format "Minute Hour Day_of_month Month_of_year Day_of_week Year" |
121 | | DELETE_AFTER | Delete old backups after X many days. Set to 0 to disable |
122 | | ENCRYPTION_ALGORITHM [^5] | Set the symmetric encryption algorithm (only used with ENCRYPTION_PASSWORD) |
123 | | ENCRYPTION_BASE64_GPG_KEY | BASE64 encoded gpg public key. Set to `false` to disable. |
124 | | ENCRYPTION_GPG_KEYFILE_LOCATION | File path of the gpg public key inside the container (should not be changed) |
125 | | ENCRYPTION_PASSWORD | Encryption password for symmetric encryption. Set to `false` to disable. |
126 | | TIMESTAMP | Set to `true` to append timestamp to the backup file |
127 | | GID | Group ID to run the cron job with |
128 | | GNUPGHOME | GNUPG home folder inside the container (should not be changed) |
129 | | GNUPGHOME_PERMISSIONS | Permissions of the GNUPGHOME folder (should not be changed) |
130 | | HEALTHCHECK_URL | Set a healthcheck url like |
131 | | HEALTHCHECK_FILE | Set the path of the local healtcheck (container health) file |
132 | | HEALTHCHECK_FILE_PERMISSIONS | Set the permissions of the local healtcheck (container health) file |
133 | | LOG_LEVEL | DEBUG, INFO, WARN, ERROR, CRITICAL are supported |
134 | | LOG_DIR | Path to the logfile folder *inside* the container |
135 | | LOG_DIR_PERMISSIONS | Set the permissions of the logfile folder. Set to -1 to disable. |
136 | | TZ | Set the timezone inside the container [^2] |
137 | | UID | User ID to run the cron job with |
138 | | VW_DATA_FOLDER [^4] | Set the location of the vaultwarden data folder *inside* the container |
139 | | VW_DATABASE_URL [^4] | Set the location of the vaultwarden database file *inside* the container |
140 | | VW_ATTACHMENTS_FOLDER [^4] | Set the location of the vaultwarden attachments folder *inside* the container |
141 | | VW_ICON_CACHE_FOLDER [^4] | Set the location of the vaultwarden icon cache folder *inside* the container |
142 |
143 | [^1]: The permissions should at least be 700 since the backup folder itself gets the same permissions and with 600 it would not be accessible.
144 | [^2]: see for more information
145 | [^3]: See for more details
146 | [^4]: See for more details
147 | [^5]: See `gpg --version` for possible options.
148 |
149 | ## FAQ
150 |
151 | ### I have deduplication enabled but backups are created even if there were no changes
152 |
153 | The Vaultwarden database and files can change even if there were not changes in the entries itself.
154 | For example there are values such as `last_used` which are altered even if you only access an entry (see #33 for more details). I decided to **not** include an ignore filter or similar to ignore these changes, because this would likely break when vaultwarden makes a change to the database structure.
155 | For me it's more important to have a working backup than to save a few kilobytes.
156 | Therefore the deduplication feature might not work as you expect.
157 |
158 | ### I get an error like "unable to open database file"
159 |
160 | `Error: unable to open database file` is most likely caused by permission errors.
161 | Note that sqlite3 creates a lock file in the source directory while running the backup.
162 | So source *AND* destination have to be +rw for the user. You can set the user and group ID
163 | via the `UID` and `GID` environment variables like described above.
164 |
165 | ### Database is locked
166 |
167 | `Error: database is locked` is most likely caused by choosing a backup location that is *not* on the same filesystem as the vaultwarden database (like a network filesystem).
168 |
169 | Vaultwarden, when started with default settings, uses WAL (write-ahed logging). You can verify this by looking for a `db.sqlite3-wal` file in the same folder as your original database file. According to the official SQLite docs WAL will cause issues in network share scenarios (see https://www.sqlite.org/wal.html):
170 |
171 | > All processes using a database must be on the same host computer; WAL does not work over a network filesystem.
172 |
173 | Basically there are two workarounds for this issue
174 |
175 | 1. Choose a local target for your backup and then use some other tool like `cp` or `rsync` to copy the backup file to your network filesystem.
176 | 2. Disable WAL in Vaultwarden. You can find a guide here (https://github.com/dani-garcia/vaultwarden/wiki/Running-without-WAL-enabled).
177 |
178 | ### I get an error like "encryption failed: Permission denied" or "find /backup/date-time.tar.xz: Permission denied"
179 |
180 | `gpg: [stdin] encryption failed: Permission denied` is most likey caused by incorrect permissions on the /backup directory.
181 | If the `BACKUP_DIR_PERMISSIONS` environmental variable is set to `-1`, the permissions for the backups directory on the host machine must be at least xx3.
182 |
183 | ### Date Time issues / Wrong timestamp
184 |
185 | If you need timestamps in your local timezone you should mount `/etc/timezone:/etc/timezone:ro` and `/etc/localtime:/etc/localtime:ro`
186 | like it's done in the [docker-compose.yml](docker-compose.yml). An other possible solution is to set the environment variable accordingly (like `TZ=Europe/Berlin`)
187 | (see for more information).
188 |
189 | **Attention** if you are on an ARM based platform please note that [alpine](https://alpinelinux.org/) is used as base image for this project to keep things small. Since alpine 3.13 and above it's possible that you will end up with a container with broken time and date settings (i.e. year 1900). This is a known problem in the alpine project (see [Github issue](https://github.com/alpinelinux/docker-alpine/issues/141) and [solution](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements)) and there is nothing I can do about it. However in the [alpine wiki](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements) a solution is being proposed which I also tested tested on my raspberry pi. After following the described process it started working again as expected. If you still experience issues or could for some reason not apply the aforementioned fixes please feel free to open an issue.
190 |
191 | ### Why is the container started by the root user?
192 |
193 | The main reason to build this image was to allow users to run sheduled tasks where their host OS does not allow them to do so, or where they want a "portable" way of using a scheduled tasks without relying on host OS mechanisms.
194 |
195 | Since `crond` *must* be run as root user there is no way to start this container as a non-root user while using cron. I'm aware that there are other task schedulers like [supercronic](https://github.com/aptible/supercronic) which allow to run without root privileges but I want to stay with the standard and established cron system for the time being.
196 |
197 | ### Why sh is used instead of bash
198 |
199 | Alpine by default comes without bash installed. Since the pre-installed `ash` shell is suitable for the tasks of this image and comes with no need to install additional tools like bash, `/bin/sh` is used as shell. The scripts also aims to be POSIX compliant which should make a switch of the base image fairly easy, if needed.
200 |
--------------------------------------------------------------------------------
/docker-compose.dev.yml:
--------------------------------------------------------------------------------
1 | services:
2 | vaultwarden:
3 | image: vaultwarden/server
4 | container_name: vaultwarden
5 | user: 1000:1000
6 | ports:
7 | - 8002:8080
8 | volumes:
9 | - ./vw-data/:/data/
10 | restart: on-failure
11 | environment:
12 | - ROCKET_PORT=8080
13 |
14 | vaultwarden-backup:
15 | container_name: vaultwarden-backup
16 | build: .
17 | #user: 1000:1000
18 | restart: on-failure
19 | init: true
20 | depends_on:
21 | - vaultwarden
22 | volumes:
23 | - ./vw-data:/data/
24 | - ./test:/backup
25 | - /etc/timezone:/etc/timezone:ro
26 | - /etc/localtime:/etc/localtime:ro
27 | environment:
28 | - BACKUP_ADD_DATABASE=true
29 | - BACKUP_ADD_ATTACHMENTS=true
30 | - BACKUP_ADD_CONFIG_JSON=true
31 | - BACKUP_USE_DEDUPE=true
32 | #- DELETE_AFTER=1
33 | - TIMESTAMP=false
34 | - CRON_TIME=*/1 * * * *
35 | - TZ=Europe/Berlin
36 | - UID=1000
37 | - GID=1000
38 | - BACKUP_DIR=/backup
39 | #- BACKUP_DIR_PERMISSIONS=777
40 | #- BACKUP_DIR_PERMISSIONS=-1
41 | #- LOG_DIR_PERMISSIONS=-1
42 | - LOG_DIR=/backup/logs
43 | - LOG_LEVEL=INFO
44 | - LOG_CLEAR_AT_START=true
45 | - BACKUP_ON_STARTUP=true
46 | #- ENCRYPTION_PASSWORD=testtest
47 | #- ENCRYPTION_BASE64_GPG_KEY="LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkdQeEJ4QUJFQUM4M0lKdW5yZllaSUZROGNtYS9VVWQ0blF3VjdtZUxsSXhSbFN5cVJRaW9vbGZuUXUvCjZoMTYvcGErVkRYSERFMXhFL014SGRjSGFPZTdMNXc4L1F0Z094ZXhpUlF4MklOcVhnWUdjeThjY3M0UjhMaEYKZENlZmsveWhMN2x4dEFYcTVwWHZabVY4QlA1SE5ESFRUMUExZEw4T0ZodVpLWnk2QisrNGFEZ2o1TzFhUlY5bwpDOGhjVWJVOTRXNHQ1YlBVbFVsMmNMSTU0am1wUWF3eFBTWHkwZGIzOE5PSXN3bG9zOWh4TTQ4SUFBM09MS09xCjBDYVUrV2EvRC9ydUNtSkl4a3pObTc5NFJudGdsTkFmZHVRK3djdVFRMCtSWE1ZWVIvQTk4cUNJVi8vU3hXMWQKd0dadW5kaXJUcXZLdTNSZkJzNFluSHV6MjlWOEVUb0pKR3M2cXBSM29OL1FnbEhKMVZydDhxNHhXQ0l3NUtSSQo5UExneTFaTjZBd2tCYXVrRlExNjdLVnQ5TmY2elJEeG9ZUnN3dXREdkthQVJRdUNuRU1ucXp2WWorRnI5WjdHCjQ3YytIb3hVcGhGblRxOC8xWVd1T3VnMkpua2FOOXNtVTEwK3U0eDNMejVwRnU0MmNlVC9sRUZqeDJyYno4dmQKZG1NemZtc1lQVUcrQkNlbUdualhEelo5MVZtUTkvcnhXMjFNYWZBa2hoM2VUaTB3cEIwelNnOXVFUDVpazV1SgpONXpSeDIzTHlUYzV1N3QzTEx5VGxVZHNBUElUQWhoWDdGa2g1MGxKeHJDcURaNkduaXRva1ZXZjJZOWlobnpCCjdXQ25JMUVacGV5YnFVRjZSVlNPWjB2eXJrclBKazNLaGo0aVJRdzBZbXgyZkxURDFHdlVUL1Y0SVFBUkFRQUIKdENaVVpYTjBJRlZ6WlhJZ0tFNXZJRU52YlcxbGJuUXBJRHgwWlhOMFFIUmxjM1F1WTI5dFBva0NUZ1FUQVFvQQpPQlloQkYvenVNMGVSSEJCNVlUS1lxK05qMENVR3Bvc0JRSmo4UWNRQWhzREJRc0pDQWNDQmhVS0NRZ0xBZ1FXCkFnTUJBaDRCQWhlQUFBb0pFSytOajBDVUdwb3NvellQL1JMUG5YRmk5U3RzWVJ5K1RuVEZmM1ZoNDNvZlV2YUUKa0l5ekFHL3JTaEFQdnVUR0tHRmtyaEFtNHJYWGFtUFdiL0o2N01kRWQrN0ErMklLcWV1NVNUK3d3a2x2RmpiZAp1RHREeFEwSmVOM2Q4RlFRdlFTSWhBemMxUVozWTh6VW1aSlI5WnFoaGJvWkl1MDhDUHZlK1oyYWhaL2JHdHBNCkZ1ZEVZbFA5ZG1wSFJDT3pxQ01Ia1BoOFc2MkJWUEt3K29rYTZQRUU4dXBpamh1dmV3M3NxSURISHhpQVVBZmsKZDZsUDJYSEVuWU1FcG9aa3V1Wk9GK0FzMjR6NnAzZ0Y3TzA0dzNlaXJMeVpDNDlmcTNJZlNaMGtiOHFLdTZnNwpqTEhLQ2xNcmh6S1NkVTR4S3NjSG9mRllHSXM4Ny9YRzdtdjJCbmpnTGlhNTNkVUs4UWhmUktUbW9nYTRYdmlsCjYzRWhVSVp0QXR4Vzcxd2hOT3FZa20wR0RSRTVhNlRnK29TbWpHYnNJL2NUWGZIdHRNMitJLy9udzRYOVQ4SVEKeGllK1VOQWROb25GSk43M2t4dWEvUi9HamhFY1pVRUlvdDNNa2trTGE5M0VOSUpFaXNBMlQ5dmJMc2ttNlpyQgpmZ3VXei9XZUwxaURYdU5LbU9LMkdaMG1rQWxOaHVQc1BDUi84V0pjSzVhRFJYVkMxcytFaHU0NVVQZVFrc3d4CklSSzE0cTRtRldDWHpNa1JGeXNxY2hORFo1RjVDWVZJa0J2d0NDMmZ2M3E2a05RVUVUN2JZN3hrNDdzL05HUW0KVlQzcTJzM3NzOC9ESWpJOUd4RCs3aHZmMC9PNXA5eUpTZ1pWRnAvc2tNNmh2STgwaHExRlBQWnZMVVR0OWMyegpCQkZNekRvYVhvSGx1UUlOQkdQeEJ4QUJFQUMvbVNvaTlTNU53R3F0Q211NjdmbWo3WHc5c2ZOWFphclplS0dJCm1LTkhaSFNTdU04NWxEOFhTQ2JNa2RTN2ZyRUZOa2hUa0ZoNXREZEJhTGE5KzFMR1IzZnNZdFpMSDdQOWUvaFQKUjVwUHY4OEpIeFJ0elFZVTNYMmY2Z1piNlBpWExPTTdBc2Z2VlR4Y0l0eEk2K0ZBT08vWXhuTWJxL0tYNnhIYQp4U2x3aTZXM3c4M205UkFUVFQxUWppOU5XcEdZRWtuTkhFK2UzL1F2SWFhRUx5dmY0R3NaUndZMzB1ZDBxM2VGCk5pNENORCtjZXJIOUc4ZWNZaHM0aVV6d29LdWtuUXBOdlc5eGdrZmRKdEZxSm5ITEphNVprYnQvQVRKdmVPQ3UKaG1mdDAxVHcrMXlaSCtFNXdXN2EvbnBoUnV1aXJEWHRaUCswYVdCQ1Y5SUluMHI3SG56eEhhTkEzSEZFNDNvcwpxNzVaaVZXemZMTnQvdWhjSGJocWJmWGdwMDZKUUxxQ0g1dGp1QnJISjZlRlFsZ2FWZ2IrWXc2WUZWZTBQK0JRCjZnWnhpblU5OTkzK2JBN2NzTmZNY2s4eU00OWVib3lHUVh0cmZJTDkxdjNOVDhVOCttQVRDZXEzVWVtQlNIUWwKVTBieHJGTkFrdnc2VnQ3NjBCQlhCOTRDQ3VYVkY4bmM0M2ZKaVN4ZGp5M0hKdVIxVTJTYU1wZEZ5aFlFVkNWSApIUk9uOVJxd1B5c1B6T2oxbWFETko3a2J5SnFDL1ZsZEt3YUFuM2ZDKy9IMnZIdzBmQzRVOG42Y1MyVzllM3kyCjVORTlwcEtINXc5bU9ITEsydUV2anJoZFA4L3hXUFJNcm81YlE4L2RCSWIwT0crYVVuRzVUNlBVTmFTa2djNU8KV0luQ093QVJBUUFCaVFJMkJCZ0JDZ0FnRmlFRVgvTzR6UjVFY0VIbGhNcGlyNDJQUUpRYW1pd0ZBbVB4QnhBQwpHd3dBQ2drUXI0MlBRSlFhbWl3aERRLzlHaEw0M3huQlI1bHRyaE1DcDlYOXU5ZkRpQ1ZDWXk1TGFibDdmQ0FQCjgxNjNhWWtrc1U0NFpjeGs2ZHNFU1dUdXM1M2MzY0x4c3VNU0ZIazVqR000K0RBRzBiWnVnMDRPdkp2R2pWUE8Kc2p4YzFRRllPMFJRdW9PeThSU2VYRmpmK2FhdWc3N2Y2S3BOc1EvSGpQbEtiVktsTTdZcHdaaU5xY3l1WEtzagpaNTNnc05qN292Snl5RFdIVU9ISzZWWXdWVFdMeFQ2bjdNa2tWdHRjcVNjaTFqYlZZVjBQVnc3bEhzMlVITis4CmNkM2tnNm9RYXF5Y1RRRmp4KzQ5NWkrNnRpTVJtTTJRMHozVkJIU0FJKzVuUEc5Tzh3T3FBeVBRUk9nMmV3dGgKdWl4WmJUcTh1dHhpTWFTU1VuK211VlVhSWlvQ0thSUxPUjlIay91d1U5NUZtMVF2c3EvVFJ5OTJlSElsZEt5SAowcDc5YUtjRnFkbHA2T0pXN2x1eDI5YUhiMDhSVGpNT0pWM2xNdjVQTG9lK1NaTTM5a3QzMUJCcDlsaEdnVFJyCkxmOHJjOFczcFh4V0ZyUnNubm5XVXJrSnJKYWswK3plaWRxc2N5clZNb3l4UElRWHZZODFxRjNXYTdvR2x5eEIKVjZXREFTWlJYaVNJU0JPWnVMZlJSUWxseTc2M2oyQmFvNWJPeEZXdlNFZVdCUUhRQzFOOEFtNG9UVzE1Vmhvdwp6SS8yeVFPZEtMSzVSSlRwaFgrbjkyelovb25DUjVTMmRHYklvWno2YUJLYnp1QUdMdWUxTUo4YTIwRUgwZmlsCkowYzYvMlZwcmZBRGdUV2ZGRExNN0psU2xKVzNpYjlOVU5CSzAySnJnYzlOc1NiRUxWamUvcldVekhSeUVSQTUKbUZvPQo9ZUhDdwotLS0tLUVORCBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCg=="
48 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | services:
2 | vaultwarden:
3 | image: vaultwarden/server
4 | container_name: vaultwarden
5 | ports:
6 | - 8002:80
7 | volumes:
8 | - vaultwarden:/data/
9 | restart: on-failure
10 | env_file:
11 | - .env
12 |
13 | vaultwarden-backup:
14 | image: bruceforce/vaultwarden-backup
15 | restart: on-failure
16 | init: true
17 | depends_on:
18 | - vaultwarden
19 | volumes:
20 | - vaultwarden:/data/
21 | # uncomment this if you want your backup to be written to ./backup/ folder"
22 | # - ./backup:/backup/
23 | env_file:
24 | - .env
25 |
26 | volumes:
27 | vaultwarden:
28 |
--------------------------------------------------------------------------------
/src/app/backup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # shellcheck disable=SC1091
4 |
5 | . /opt/scripts/logging.sh
6 | . /opt/scripts/set-env.sh
7 | . /opt/scripts/helper.sh
8 | : "${warning_counter:=0}"
9 | : "${error_counter:=0}"
10 |
11 | ### Functions ###
12 | #######################################
13 | # Initializes variables
14 | # Arguments:
15 | # None
16 | # Returns:
17 | # None
18 | #######################################
19 | init() {
20 | if [ "$TIMESTAMP" = true ]; then
21 | TIMESTAMP_PREFIX="$(date "+%F-%H%M%S")_"
22 | fi
23 |
24 | if [ "$BACKUP_USE_DEDUPE" = true ]; then source_config; fi
25 |
26 | TEMP_BACKUP_DIR=/tmp/backupfiles
27 | TEMP_BACKUP_ARCHIVE="/tmp/temp-backup.tar.xz"
28 | BACKUP_FILE_DB="$TEMP_BACKUP_DIR/db.sqlite3"
29 | BACKUP_FILE_ARCHIVE="$BACKUP_DIR/${TIMESTAMP_PREFIX}backup.tar.xz"
30 | BACKUP_FILE_REGEX=".*backup\.tar\.xz\(\.gpg\)\?" # search for previous backup files matching these patterns
31 | ENCRYPTION_MODE="none"
32 | mkdir "$TEMP_BACKUP_DIR"
33 |
34 | # Add ".gpg" extension if encryption is used
35 | if [ "$ENCRYPTION_BASE64_GPG_KEY" != false ] || [ "$ENCRYPTION_PASSWORD" != false ]; then
36 | BACKUP_FILE_ARCHIVE="$BACKUP_DIR/${TIMESTAMP_PREFIX}backup.tar.xz.gpg"
37 | fi
38 |
39 | # Determine encryption mode
40 | if [ "$ENCRYPTION_BASE64_GPG_KEY" != false ] && [ "$ENCRYPTION_PASSWORD" != false ]; then
41 | warn "Ignoring ENCRYPTION_PASSWORD since you set both ENCRYPTION_BASE64_GPG_KEY and ENCRYPTION_PASSWORD."
42 | ENCRYPTION_MODE="asymmetric"
43 | elif [ -f "$ENCRYPTION_GPG_KEYFILE_LOCATION" ]; then
44 | ENCRYPTION_MODE="asymmetric"
45 | elif [ ! "$ENCRYPTION_PASSWORD" = false ]; then
46 | ENCRYPTION_MODE="symmetric"
47 | fi
48 |
49 | if [ ! -f "$VW_DATABASE_URL" ]; then
50 | printf 1 > "$HEALTHCHECK_FILE"
51 | critical "Database $VW_DATABASE_URL not found! Please check if you mounted the vaultwarden volume (in docker-compose or with '--volumes-from=vaultwarden'!)"
52 | fi
53 | }
54 |
55 | #######################################
56 | # Creates a temporary archive.
57 | # This archive is used afterwards depending on the backup mode
58 | # (simple, symmetric encrypted, asymmetric encrypted).
59 | # Arguments:
60 | # None
61 | # Returns:
62 | # None
63 | #######################################
64 | create_temporary_archive() {
65 | # First we backup the database to a temporary file (this will later be added to a tar archive)
66 | if [ "$BACKUP_ADD_DATABASE" = true ] && /usr/bin/sqlite3 "$VW_DATABASE_URL" ".backup '$BACKUP_FILE_DB'"; then
67 | debug "Written temporary database backup file to $BACKUP_FILE_DB"
68 | else
69 | error "Backup of the database failed"
70 | fi
71 |
72 | # Copy all files to a temporary location. This makes calculating hashsums and building the tar archive easier.
73 | if [ "$BACKUP_ADD_ATTACHMENTS" = true ] && [ -e "$VW_ATTACHMENTS_FOLDER" ]; then cp -a "$VW_ATTACHMENTS_FOLDER" "$TEMP_BACKUP_DIR"; fi
74 | if [ "$BACKUP_ADD_ICON_CACHE" = true ] && [ -e "$VW_ICON_CACHE_FOLDER" ]; then cp -a "$VW_ICON_CACHE_FOLDER" "$TEMP_BACKUP_DIR"; fi
75 | if [ "$BACKUP_ADD_SENDS" = true ] && [ -e "$VW_DATA_FOLDER/sends" ]; then cp -a "$VW_DATA_FOLDER/sends" "$TEMP_BACKUP_DIR/sends"; fi
76 | if [ "$BACKUP_ADD_CONFIG_JSON" = true ] && [ -e "$VW_DATA_FOLDER/config.json" ]; then cp -a "$VW_DATA_FOLDER/config.json" "$TEMP_BACKUP_DIR/config.json"; fi
77 | if [ "$BACKUP_ADD_RSA_KEY" = true ]; then find "$VW_DATA_FOLDER" -iname 'rsa_key*' -exec cp -a {} "$TEMP_BACKUP_DIR" \;; fi
78 |
79 | # Create a temporary unencrypted backup archive
80 | debug "Current tar command: /bin/tar -cJf $TEMP_BACKUP_ARCHIVE -C $TEMP_BACKUP_DIR" .
81 | if eval /bin/tar -cJf "$TEMP_BACKUP_ARCHIVE" -C "$TEMP_BACKUP_DIR" .; then
82 | debug "Written temporary tar archive to $TEMP_BACKUP_ARCHIVE"
83 | else
84 | error "Database backup failed"
85 | fi
86 |
87 | if [ "$BACKUP_USE_DEDUPE" = true ]; then
88 | # Generate hash of the files and store it in configuration file
89 | latest_backup_contenthash=$(find "$TEMP_BACKUP_DIR" -type f -exec "$BACKUP_HASHING_EXEC" {} \; | LC_ALL=C sort | sha256sum | awk '{print $1}')
90 | update_config "contenthash" "$latest_backup_contenthash"
91 | fi
92 | }
93 |
94 |
95 | #######################################
96 | # Function to create a simple backup without encryption
97 | # Arguments:
98 | # None
99 | # Returns:
100 | # 0 if the backup was successful
101 | #######################################
102 | create_simple_backup() {
103 | create_temporary_archive
104 | debug "Creating backup without encryption"
105 | create_new_backup=true
106 |
107 | # If DEDUPE is enabled, a previous backup exists, and the contents have NOT changed, then copy the previous backup
108 | if [ "$BACKUP_USE_DEDUPE" = true ]; then
109 | if is_enc_mode_changed || is_backup_content_changed; then
110 | info "Changes detected since last backup. Creating new backup file."
111 | else
112 | info "No changes detected since last backup. Dedupe enabled. No new backup file was created."
113 | create_new_backup=false
114 | fi
115 | fi
116 |
117 | if [ "$create_new_backup" = true ]; then
118 | if eval cp -a "$TEMP_BACKUP_ARCHIVE" "$BACKUP_FILE_ARCHIVE"; then
119 | info "Successfully created backup"
120 | return 0
121 | else
122 | error "Failed to create backup!"
123 | return 1
124 | fi
125 | fi
126 |
127 | return 2
128 | }
129 |
130 | #######################################
131 | # Function to create a backup with asymmetric encryption
132 | # Arguments:
133 | # None
134 | # Returns:
135 | # 0 if the backup was successful
136 | #######################################
137 | create_asym_encrypted_backup() {
138 | create_temporary_archive
139 | debug "Encrypting using GPG Keyfile"
140 | create_new_backup=true
141 |
142 | if [ "$BACKUP_USE_DEDUPE" = true ]; then
143 | if is_asym_key_changed || is_enc_mode_changed || is_backup_content_changed; then
144 | info "Changes detected since last backup (either key or backup content changed). Creating new backup file."
145 | else
146 | info "No changes detected since last backup. Dedupe enabled. No new backup file was created."
147 | create_new_backup=false
148 | fi
149 | fi
150 |
151 | if [ "$create_new_backup" = true ]; then
152 | # Create a backup with public key encryption
153 | if eval gpg --batch --no-options --no-tty --yes --recipient-file "$ENCRYPTION_GPG_KEYFILE_LOCATION" \
154 | -o "$BACKUP_FILE_ARCHIVE" --encrypt "$TEMP_BACKUP_ARCHIVE"; then
155 | info "Successfully created gpg (public key) encrypted backup $BACKUP_FILE_ARCHIVE"
156 | return 0
157 | else
158 | error "Encrypted backup failed!"
159 | return 1
160 | fi
161 | fi
162 |
163 | return 2
164 | }
165 |
166 | #######################################
167 | # Function to create a backup with symmetric encryption
168 | # Arguments:
169 | # None
170 | # Returns:
171 | # 0 if the backup was successful
172 | #######################################
173 | create_sym_encrypted_backup() {
174 | create_temporary_archive
175 | debug "Creating backup using passphrase"
176 | create_new_backup=true
177 |
178 | if [ "$BACKUP_USE_DEDUPE" = true ]; then
179 | if is_sym_key_changed || is_enc_mode_changed || is_backup_content_changed; then
180 | info "Changes detected since last backup (either key or backup content changed). Creating new backup file."
181 | else
182 | info "No changes detected since last backup. Dedupe enabled. No new backup file was created."
183 | create_new_backup=false
184 | fi
185 | fi
186 |
187 | # Create a backup with symmetric encryption
188 | if [ "$create_new_backup" = true ]; then
189 | debug "Creating backup with symmetric encryption"
190 | if gpg --batch --no-options --no-tty --yes --symmetric --passphrase "$ENCRYPTION_PASSWORD" \
191 | --cipher-algo "$ENCRYPTION_ALGORITHM" -o "$BACKUP_FILE_ARCHIVE" "$TEMP_BACKUP_ARCHIVE"; then
192 | info "Successfully created gpg (password) encrypted backup $BACKUP_FILE_ARCHIVE"
193 | return 0
194 | else
195 | error "Encrypted backup failed!"
196 | return 1
197 | fi
198 | fi
199 |
200 | return 2
201 | }
202 |
203 | #######################################
204 | # Main function to backup database and
205 | # additional data like attachments, sends, etc.
206 | # Arguments:
207 | # None
208 | # Returns:
209 | # None
210 | #######################################
211 | backup() {
212 | if [ "$ENCRYPTION_MODE" = "asymmetric" ]; then
213 | create_asym_encrypted_backup
214 | rc=$?
215 | elif [ "$ENCRYPTION_MODE" = "symmetric" ]; then
216 | create_sym_encrypted_backup
217 | rc=$?
218 | elif [ "$ENCRYPTION_MODE" = "none" ]; then
219 | create_simple_backup
220 | rc=$?
221 | fi
222 |
223 | if [ "$BACKUP_USE_DEDUPE" = true ] && [ "$rc" -eq 0 ]; then
224 | debug "Updating $BACKUP_INI after successful backup."
225 | update_config "last_backup_file" "$BACKUP_FILE_ARCHIVE"
226 | update_config "tarhash" "$("$BACKUP_HASHING_EXEC" "$BACKUP_FILE_ARCHIVE" | awk '{print $1}')"
227 | update_config "last_encryption_mode" "$ENCRYPTION_MODE"
228 | fi
229 |
230 | # Remove temporary files
231 | rm -rf "$TEMP_BACKUP_DIR"
232 | rm "$TEMP_BACKUP_ARCHIVE"
233 | }
234 |
235 | #######################################
236 | # Performs a health check
237 | # Arguments:
238 | # None
239 | # Returns:
240 | # None
241 | #######################################
242 | perform_healthcheck() {
243 | debug "\$error_counter=$error_counter"
244 |
245 | if [ "$error_counter" -ne 0 ]; then
246 | warn "There were $error_counter errors during backup. Not sending health check ping."
247 | printf 1 > "$HEALTHCHECK_FILE"
248 | return 1
249 | fi
250 |
251 | # At this point the container is healthy. So we create a health-check file used to determine container health
252 | # and send a health check ping if the HEALTHCHECK_URL is set.
253 | printf 0 > "$HEALTHCHECK_FILE"
254 | debug "Evaluating \$HEALTHCHECK_URL"
255 | if [ -z "$HEALTHCHECK_URL" ]; then
256 | debug "Variable \$HEALTHCHECK_URL not set. Skipping health check."
257 | return 0
258 | fi
259 |
260 | info "Sending health check ping."
261 | wget "$HEALTHCHECK_URL" -T 10 -t 5 -q -O /dev/null
262 | }
263 |
264 | #######################################
265 | # Cleans up old backups after specified
266 | # amount of time. Always keeps at least 1 backup.
267 | # Arguments:
268 | # None
269 | # Returns:
270 | # None
271 | #######################################
272 | cleanup() {
273 | if [ -n "$DELETE_AFTER" ] && [ "$DELETE_AFTER" -gt 0 ]; then
274 | if [ "$TIMESTAMP" != true ]; then warn "DELETE_AFTER will most likely have no effect because TIMESTAMP is not set to true."; fi
275 | newest_file=$(find "$BACKUP_DIR" -type f -regex "$BACKUP_FILE_REGEX" -exec stat -c "%Y %n" {} + | sort -n | tail -n 1 | cut -d " " -f 2-)
276 | find "$BACKUP_DIR" -type f -regex "$BACKUP_FILE_REGEX" -mtime +"$DELETE_AFTER" ! -path "$newest_file" -exec sh -c '
277 | . /opt/scripts/logging.sh
278 |
279 | rm -f $@
280 | info "Deleted backups after $DELETE_AFTER days: $@"
281 | ' shell {} \;
282 | fi
283 | }
284 |
285 | ### Main ###
286 |
287 | # Run init
288 | init
289 |
290 | # Run the backup command
291 | backup
292 |
293 | # Perform healthcheck
294 | perform_healthcheck
295 |
296 | # Delete backup files after $DELETE_AFTER days.
297 | cleanup
298 |
--------------------------------------------------------------------------------
/src/opt/scripts/helper.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # shellcheck disable=SC1091
4 |
5 | . /opt/scripts/logging.sh
6 | . /opt/scripts/set-env.sh
7 | : "${warning_counter:=0}"
8 | : "${error_counter:=0}"
9 |
10 | #######################################
11 | # Update config file
12 | # Arguments:
13 | # $1 key to update
14 | # $2 value of the key
15 | # Returns:
16 | # None
17 | #######################################
18 | update_config() {
19 | key="$1"
20 | new_value="$2"
21 |
22 | debug "key: $1"
23 | debug "new_value: $2"
24 |
25 | # Check if the key already exists in the configuration file
26 |
27 | if grep -q "^$key\s*=" "$BACKUP_INI"; then
28 | # Key exists, update the value
29 | sed -i "s@^\($key\s*=\s*\).*@\1$new_value@" "$BACKUP_INI"
30 | else
31 | # Key does not exist, add a new line
32 | echo "$key=$new_value" >> "$BACKUP_INI"
33 | fi
34 | }
35 |
36 |
37 | #######################################
38 | # Source config file for dedupe mode
39 | # Arguments:
40 | # None
41 | # Returns:
42 | # None
43 | #######################################
44 | source_config() {
45 | debug "Sourcing ini file to get dedupe info."
46 | # shellcheck disable=SC1090
47 | if [ -f "$BACKUP_INI" ]; then
48 | . "$BACKUP_INI"
49 | else
50 | critical "Configuration file not found!"
51 | fi
52 | }
53 |
54 | #######################################
55 | # Check if the encryption mode of the backup has changed.
56 | # Arguments:
57 | # None
58 | # Returns:
59 | # 0 if the encryption mode of the backup has changed since last run
60 | # 1 if not
61 | #######################################
62 | is_enc_mode_changed() {
63 | if [ "${last_encryption_mode:-UNDEFINED}" != "$ENCRYPTION_MODE" ]; then
64 | debug "Encryption mode changed. Returning 0"
65 | return 0
66 | fi
67 |
68 | return 1
69 | }
70 |
71 | #######################################
72 | # Check if the content of the backup has changed.
73 | # This is done by creating a hash of all files
74 | # and hashing this again to make sure that there
75 | # are no changes in existing files and also no new files were added.
76 | # Arguments:
77 | # None
78 | # Returns:
79 | # 0 if the content of the backup has changed since last run
80 | # 1 if not
81 | #######################################
82 | is_backup_content_changed() {
83 | if [ ! -f "${last_backup_file:-UNDEFINED}" ]; then
84 | debug "Unknown status of last backup. Returning 0"
85 | return 0
86 | fi
87 |
88 | # Calculate the hash of the latest stored backup file - this should never change unsless the file is corrupted
89 | latest_backup_tarhash=$("$BACKUP_HASHING_EXEC" "${last_backup_file:-UNDEFINED}" | awk '{print $1}' )
90 | # Calculates a hashes of all individual backup files in the temporary backup dir. Then calculates a single hash over all the hashes of the files.
91 | latest_backup_contenthash=$(find "$TEMP_BACKUP_DIR" -type f -exec "$BACKUP_HASHING_EXEC" {} \; | LC_ALL=C sort | "$BACKUP_HASHING_EXEC" | awk '{print $1}')
92 |
93 | debug "stored tarhash: ${tarhash:-UNDEFINED}"
94 | debug "latest tarhash: $latest_backup_tarhash"
95 | debug "stored contenthash: ${contenthash:-UNDEFINED}"
96 | debug "latest contenthash $latest_backup_contenthash"
97 |
98 | # If tar hashes differ return success (0) --> backed up archives have changed and might be corrupted
99 | if [ "$tarhash" != "$latest_backup_tarhash" ]; then
100 | debug "Backed up archives have changed and might be corrupted. Returning 0"
101 | return 0
102 | fi
103 |
104 | # If content hashes differ return success (0) --> files have changed
105 | if [ "$contenthash" != "$latest_backup_contenthash" ]; then
106 | debug "File contents changed. Returning 0"
107 | return 0
108 | fi
109 |
110 | debug "File contents have not changed. Returning 1"
111 | return 1
112 | }
113 |
114 | #######################################
115 | # Check if the asymmetric key changed
116 | # Arguments:
117 | # None
118 | # Returns:
119 | # 0 if the gpg asymmetric has changed since last run or no previous backup was found
120 | # 1 if not
121 | #######################################
122 | is_asym_key_changed() {
123 | debug "Checking if gpg keys have changed."
124 |
125 | if [ ! -f "${last_backup_file:-UNDEFINED}" ]; then
126 | debug "Unknown status of last backup. Returning 0"
127 | return 0
128 | fi
129 |
130 | # Get KeyID of current GPG Keyfile
131 | current_keyID="$(gpg --with-colons "$ENCRYPTION_GPG_KEYFILE_LOCATION" 2>&1 | awk -F':' '/sub/{ print $5 }')"
132 |
133 | # Get public KeyID of previous backup
134 | previous_keyID="$(gpg --pinentry-mode cancel --list-packets "${last_backup_file:-UNDEFINED}" 2>&1 | sed -n 's/.*:pubkey\s.*\skeyid \(.*\)$/\1/p')"
135 |
136 | # Check if the key IDs match.
137 | if [ "$current_keyID" != "$previous_keyID" ]; then
138 | debug "gpg keys have changed. Returning 0"
139 | return 0; fi
140 |
141 | debug "gpg keys have not changed. Returning 1"
142 | return 1
143 | }
144 |
145 | #######################################
146 | # Check if the symmetric key changed
147 | # Arguments:
148 | # None
149 | # Returns:
150 | # 0 if the key has changed since last run or no previous backup was found
151 | # 1 if not
152 | #######################################
153 | is_sym_key_changed() {
154 | debug "Checking if symmetric key has changed."
155 |
156 | if [ ! -f "${last_backup_file:-UNDEFINED}" ]; then
157 | debug "Unknown status of last backup. Returning 0"
158 | return 0
159 | fi
160 |
161 | # Attempt to decrypt previous backup with current key
162 | if gpg --decrypt --batch --dry-run --output /dev/null --passphrase "$ENCRYPTION_PASSWORD" "${last_backup_file:-UNDEFINED}" > /dev/null 2>&1; then
163 | # Previous backup key is correct
164 | debug "Passphrase is unchanged. Returning 1"
165 | return 1
166 | else
167 | debug "Passphrase has changed since the last backup! Returning 0"
168 | return 0
169 | fi
170 | }
171 |
--------------------------------------------------------------------------------
/src/opt/scripts/logging.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ### Vars ###
4 | warning_counter=0
5 | error_counter=0
6 |
7 | # Set LOG_LEVEL
8 | if [ "$LOG_LEVEL" = "DEBUG" ]; then LOG_LEVEL_NUMBER=7; fi
9 | if [ "$LOG_LEVEL" = "INFO" ]; then LOG_LEVEL_NUMBER=6; fi
10 | if [ "$LOG_LEVEL" = "WARN" ]; then LOG_LEVEL_NUMBER=4; fi
11 | if [ "$LOG_LEVEL" = "ERROR" ]; then LOG_LEVEL_NUMBER=3; fi
12 | if [ "$LOG_LEVEL" = "CRITICAL" ]; then LOG_LEVEL_NUMBER=2; fi
13 |
14 | ### Functions ###
15 |
16 | # General log format
17 | log() {
18 | printf "$(date "+%F %T") - %b\n" "$*" >> "$LOGFILE_APP"
19 | }
20 |
21 | # Debug log
22 | debug() {
23 | if [ "$LOG_LEVEL_NUMBER" -eq 7 ]; then
24 | log "DEBUG - $*"
25 | fi
26 | }
27 |
28 | # Info log
29 | info() {
30 | if [ "$LOG_LEVEL_NUMBER" -ge 6 ]; then
31 | log "INFO - $*"
32 | fi
33 | }
34 |
35 | # Warning log
36 | warn() {
37 | warning_counter=$((warning_counter + 1))
38 | if [ "$LOG_LEVEL_NUMBER" -ge 4 ]; then
39 | log "WARNING - $*"
40 | fi
41 | debug "The new warning counter is $warning_counter."
42 | }
43 |
44 | # Error log
45 | error() {
46 | error_counter=$((error_counter + 1))
47 | if [ "$LOG_LEVEL_NUMBER" -ge 3 ]; then
48 | log "ERROR - $*" 1>&2
49 | fi
50 | debug "The new error counter is $error_counter."
51 | }
52 |
53 | # Critical log
54 | critical() {
55 | error_counter=$((error_counter + 1))
56 | if [ "$LOG_LEVEL_NUMBER" -ge 2 ]; then
57 | log "CRITICAL - $*\nExiting"
58 | fi
59 | debug "The new error counter is $error_counter."
60 | cat "$LOGFILE_APP"
61 | exit 1
62 | }
63 |
--------------------------------------------------------------------------------
/src/opt/scripts/set-env.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # shellcheck disable=SC1091
4 |
5 | export LOG_LEVEL="${LOG_LEVEL:-INFO}"
6 | . /opt/scripts/logging.sh
7 | : "${warning_counter:=0}"
8 | : "${error_counter:=0}"
9 |
10 | # Functions
11 | check_deprecations() {
12 | # Warning for deprecated settings
13 | if [ -n "$BACKUP_FILE" ]; then
14 | warn "\$BACKUP_FILE is deprecated and will be removed in future versions. Please use \$BACKUP_DIR instead to specify the folder of the backup."
15 | if [ -z "$BACKUP_DIR" ]; then
16 | BACKUP_DIR=$(dirname "$BACKUP_FILE")
17 | warn "Since \$BACKUP_DIR is not set defaulting to BACKUP_DIR=$BACKUP_DIR"
18 | fi
19 | fi
20 |
21 | # Warning for deprecated settings
22 | if [ -n "$BACKUP_FILE_PERMISSIONS" ]; then
23 | warn "\$BACKUP_FILE_PERMISSIONS is deprecated and will be removed in future versions. Please use \$BACKUP_DIR_PERMISSIONS instead to specify the permissions of the backup folder."
24 | if [ -z "$BACKUP_DIR_PERMISSIONS" ]; then
25 | BACKUP_DIR_PERMISSIONS="$BACKUP_FILE_PERMISSIONS"
26 | warn "Since \$BACKUP_DIR_PERMISSIONS is not set defaulting to BACKUP_DIR_PERMISSIONS=$BACKUP_FILE_PERMISSIONS"
27 | fi
28 | fi
29 |
30 | # Warning for deprecated settings
31 | if [ -n "$DB_FILE" ]; then
32 | warn "\$DB_FILE is deprecated and will be removed in future versions. Please use \$VW_DATABASE_URL instead to specify the location of the source database file."
33 | if [ -z "$VW_DATABASE_URL" ]; then
34 | VW_DATABASE_URL="$DB_FILE"
35 | warn "Since \$VW_DATABASE_URL is not set defaulting to VW_DATABASE_URL=$DB_FILE"
36 | fi
37 | fi
38 |
39 | # Warning for deprecated settings
40 | if [ -n "$ATTACHMENT_DIR" ]; then
41 | warn "\$ATTACHMENT_DIR is deprecated and will be removed in future versions. Please use \$VW_ATTACHMENTS_FOLDER instead to specify the location of the source attachments folder."
42 | if [ -z "$VW_ATTACHMENTS_FOLDER" ]; then
43 | VW_ATTACHMENTS_FOLDER="$ATTACHMENT_DIR"
44 | warn "Since \$VW_ATTACHMENTS_FOLDER is not set defaulting to VW_ATTACHMENTS_FOLDER=$ATTACHMENT_DIR"
45 | fi
46 | fi
47 |
48 | # Warning for deprecated settings
49 | if [ -n "$LOGFILE" ]; then
50 | warn "\$LOGFILE is deprecated and will be removed in future versions. Please use \$LOG_DIR instead to specify the location of the logfile folder."
51 | if [ -z "$LOG_DIR" ]; then
52 | LOG_DIR="$(dirname "$(realpath "$LOGFILE")")"
53 | warn "Since \$LOG_DIR is not set defaulting to LOG_DIR=$LOG_DIR"
54 | fi
55 | fi
56 |
57 | # Warning for deprecated settings
58 | if [ -n "$ATTACHMENT_BACKUP_DIR" ]; then
59 | warn "\$ATTACHMENT_BACKUP_DIR is deprecated and will be removed in future versions. Attachment backups are stored in the \$BACKUP_DIR."
60 | fi
61 |
62 | # Warning for deprecated settings
63 | if [ -n "$ATTACHMENT_BACKUP_FILE" ]; then
64 | warn "\$ATTACHMENT_BACKUP_FILE is deprecated and will be removed in future versions. Attachment backups are stored in the \$BACKUP_DIR."
65 | fi
66 | }
67 |
68 | check_deprecations
69 |
70 | # Set default environment variables
71 | # Environment variables specific to this image
72 | export APP_DIR="${APP_DIR:-/app}"
73 | export APP_DIR_PERMISSIONS="${APP_DIR_PERMISSIONS:-700}"
74 | export BACKUP_DIR="${BACKUP_DIR:-/backup}"
75 | export BACKUP_DIR_PERMISSIONS="${BACKUP_DIR_PERMISSIONS:-700}"
76 | export BACKUP_ON_STARTUP="${BACKUP_ON_STARTUP:-false}"
77 | export BACKUP_USE_DEDUPE="${BACKUP_USE_DEDUPE:-false}"
78 | export BACKUP_HASHING_ALGORITHM="${BACKUP_HASHING_ALGORITHM:-sha256}"
79 | export BACKUP_HASHING_EXEC="${BACKUP_HASHING_EXEC:-"$BACKUP_HASHING_ALGORITHM"sum}"
80 | export BACKUP_INI="${BACKUP_INI:-$BACKUP_DIR/vaultwarden-backup.ini}"
81 | export CRONFILE="${CRONFILE:-/etc/crontabs/root}"
82 | export CRON_TIME="${CRON_TIME:-0 5 * * *}"
83 | export DELETE_AFTER="${DELETE_AFTER:-0}"
84 | export ENCRYPTION_ALGORITHM="${ENCRYPTION_ALGORITHM:-AES256}"
85 | export ENCRYPTION_BASE64_GPG_KEY="${ENCRYPTION_BASE64_GPG_KEY:-false}"
86 | export ENCRYPTION_GPG_KEYFILE_LOCATION="${ENCRYPTION_GPG_KEYFILE_LOCATION:-$APP_DIR/encryption_key.asc}"
87 | export ENCRYPTION_PASSWORD="${ENCRYPTION_PASSWORD:-false}"
88 | export GID="${GID:-100}"
89 | export GNUPGHOME="${GNUPGHOME:-/tmp/gpg}"
90 | export GNUPGHOME_PERMISSIONS="${GNUPGHOME_PERMISSIONS:-700}"
91 | export HEALTHCHECK_FILE="${HEALTHCHECK_FILE:-$APP_DIR/health}"
92 | export HEALTHCHECK_FILE_PERMISSIONS="${HEALTHCHECK_FILE_PERMISSIONS:-700}"
93 | export LOGFILE_APP="${LOGFILE_APP:-$LOG_DIR/app.log}"
94 | export LOGFILE_CRON="${LOGFILE_CRON:-$LOG_DIR/cron.log}"
95 | export LOG_CLEAR_AT_START="${LOG_CLEAR_AT_START:-false}"
96 | export LOG_DIR="${LOG_DIR:-$APP_DIR/log}"
97 | export LOG_DIR_PERMISSIONS="${LOG_DIR_PERMISSIONS:-777}"
98 | export TIMESTAMP="${TIMESTAMP:-false}"
99 | export UID="${UID:-100}"
100 | export VW_BACKUP_VERSION="0.0.0-dev"
101 |
102 | # Additional backup files
103 | export BACKUP_ADD_DATABASE="${BACKUP_ADD_DATABASE:-true}"
104 | export BACKUP_ADD_ATTACHMENTS="${BACKUP_ADD_ATTACHMENTS:-true}"
105 | export BACKUP_ADD_CONFIG_JSON="${BACKUP_ADD_CONFIG_JSON:-true}"
106 | export BACKUP_ADD_ICON_CACHE="${BACKUP_ADD_ICON_CACHE:-false}"
107 | export BACKUP_ADD_RSA_KEY="${BACKUP_ADD_RSA_KEY:-true}"
108 | export BACKUP_ADD_SENDS="${BACKUP_ADD_SENDS:-false}"
109 |
110 | # Vaultwarden file locations
111 | # Defaulting to
112 | export VW_DATA_FOLDER="${VW_DATA_FOLDER:-/data}"
113 | export VW_DATABASE_URL="${VW_DATABASE_URL:-$VW_DATA_FOLDER/db.sqlite3}"
114 | export VW_ATTACHMENTS_FOLDER="${VW_ATTACHMENTS_FOLDER:-$VW_DATA_FOLDER/attachments}"
115 | export VW_ICON_CACHE_FOLDER="${VW_ICON_CACHE_FOLDER:-$VW_DATA_FOLDER/icon_cache}"
116 |
--------------------------------------------------------------------------------
/src/usr/local/bin/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # vim: tabstop=2 shiftwidth=2 expandtab
3 | # shellcheck disable=SC3028
4 | # shellcheck disable=SC1091
5 |
6 | #set -x
7 |
8 | . /opt/scripts/set-env.sh
9 |
10 | . /opt/scripts/logging.sh
11 | : "${warning_counter:=0}"
12 | : "${error_counter:=0}"
13 |
14 | # Allow start with custom commands
15 | if [ "$#" -ne 0 ] && command -v "$@" > /dev/null 2>&1; then
16 | "$@"
17 | exit 0
18 | fi
19 |
20 | BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh"
21 |
22 | debug "Running $(basename "$0") as $(id)"
23 |
24 | ### Functions ###
25 |
26 | # Permissions
27 | adjust_permissions() {
28 | if [ "$APP_DIR_PERMISSIONS" -ne -1 ]; then
29 | debug "Adjusting permissions for $APP_DIR: Setting owner $UID:$GID and permissions $APP_DIR_PERMISSIONS."
30 | chown -R "$UID:$GID" "$APP_DIR"
31 | chmod -R "$APP_DIR_PERMISSIONS" "$APP_DIR"
32 | else
33 | info "\$APP_DIR_PERMISSIONS set to -1. Skipping adjustment of permissions."
34 | fi
35 |
36 | if [ "$BACKUP_DIR_PERMISSIONS" -ne -1 ]; then
37 | debug "Adjusting permissions for $BACKUP_DIR: Setting owner $UID:$GID and permissions $BACKUP_DIR_PERMISSIONS."
38 | chown -R "$UID:$GID" "$BACKUP_DIR"
39 | chmod -R "$BACKUP_DIR_PERMISSIONS" "$BACKUP_DIR"
40 | else
41 | info "\$BACKUP_DIR_PERMISSIONS set to -1. Skipping adjustment of permissions."
42 | fi
43 |
44 | if [ "$LOG_DIR_PERMISSIONS" -ne -1 ]; then
45 | debug "Adjusting permissions for $LOG_DIR: Setting owner $UID:$GID and permissions $LOG_DIR_PERMISSIONS."
46 | chown -R "$UID:$GID" "$LOG_DIR"
47 | chmod -R "$LOG_DIR_PERMISSIONS" "$LOG_DIR"
48 | else
49 | info "\$LOG_DIR_PERMISSIONS set to -1. Skipping adjustment of permissions."
50 | fi
51 |
52 | if [ "$HEALTHCHECK_FILE_PERMISSIONS" -ne -1 ]; then
53 | debug "Adjusting permissions for $HEALTHCHECK_FILE: Setting owner $UID:$GID and permissions $HEALTHCHECK_FILE_PERMISSIONS."
54 | chown -R "$UID:$GID" "$HEALTHCHECK_FILE"
55 | chmod -R "$HEALTHCHECK_FILE_PERMISSIONS" "$HEALTHCHECK_FILE"
56 | else
57 | info "\$HEALTHCHECK_FILE_PERMISSIONS set to -1. Skipping adjustment of permissions."
58 | fi
59 | }
60 |
61 | # Initialization
62 | init_folders() {
63 | if [ -d "$LOG_DIR" ] && [ "$LOG_CLEAR_AT_START" = true ]; then
64 | rm -rf "${LOG_DIR:?}/"*
65 | debug "Purged logs."
66 | fi
67 |
68 | if [ ! -d "$LOG_DIR" ]; then
69 | debug "Creating $LOG_DIR."
70 | install -o "$UID" -g "$GID" -m "$LOG_DIR_PERMISSIONS" -d "$LOG_DIR"
71 | fi
72 |
73 | if [ ! -f "$LOGFILE_CRON" ]; then
74 | touch "$LOGFILE_CRON" && chown "$UID:$GID" "$LOGFILE_CRON"
75 | fi
76 |
77 | if [ ! -f "$LOGFILE_APP" ]; then
78 | touch "$LOGFILE_APP" && chown "$UID:$GID" "$LOGFILE_APP"
79 | fi
80 |
81 | # Dump Env if running in DEBUG mode
82 | [ "$LOG_LEVEL_NUMBER" -eq 7 ] && (set > "${LOG_DIR}/env.txt")
83 |
84 | if [ ! -d "$BACKUP_DIR" ]; then
85 | debug "Creating $BACKUP_DIR."
86 | install -o "$UID" -g "$GID" -m "$BACKUP_DIR_PERMISSIONS" -d "$BACKUP_DIR"
87 | fi
88 |
89 | if [ ! -d "$APP_DIR" ]; then
90 | debug "Creating $APP_DIR."
91 | install -o "$UID" -g "$GID" -m "$APP_DIR_PERMISSIONS" -d "$APP_DIR"
92 | fi
93 |
94 | if [ ! -f "$HEALTHCHECK_FILE" ]; then
95 | debug "Creating $HEALTHCHECK_FILE."
96 | printf 0 > "$HEALTHCHECK_FILE"
97 | fi
98 |
99 | if [ "$BACKUP_USE_DEDUPE" = true ] && [ ! -f "$BACKUP_INI" ]; then
100 | touch "$BACKUP_INI" && chown "$UID:$GID" "$BACKUP_INI"
101 | fi
102 |
103 | if [ ! "$ENCRYPTION_BASE64_GPG_KEY" = false ] || [ ! "$ENCRYPTION_PASSWORD" = false ]; then
104 | install -o "$UID" -g "$GID" -m "$GNUPGHOME_PERMISSIONS" -d "$GNUPGHOME"
105 | # Run a "dummy" gpg command to generate the keyring. The keyring is needed since gpg > v2.1
106 | su-exec "$UID:$GID" gpg --list-keys > /dev/null 2>&1
107 | fi
108 |
109 | if [ ! "$ENCRYPTION_BASE64_GPG_KEY" = false ]; then
110 | if decoded_key=$(echo "$ENCRYPTION_BASE64_GPG_KEY" | base64 -d) > /dev/null 2>&1; then
111 | debug "Saving decoded gpg public key to $ENCRYPTION_GPG_KEYFILE_LOCATION"
112 | echo "$decoded_key" > "$ENCRYPTION_GPG_KEYFILE_LOCATION"
113 | debug "Decoded public key is: \n$(cat "$ENCRYPTION_GPG_KEYFILE_LOCATION")"
114 | else
115 | critical "Decoding of \$ENCRYPTION_BASE64_GPG_KEY failed. Please ensure this is an actual base64 encoded gpg public key file."
116 | fi
117 | fi
118 | }
119 |
120 | # Initialize cron
121 | init_cron() {
122 | if [ "$(grep -c "$CRON_TIME $BACKUP_CMD" "$CRONFILE")" -eq 0 ]; then
123 | debug "(Re)initalizing $CRONFILE"
124 | debug "Writing backup command \"$BACKUP_CMD\" to $CRONFILE."
125 | echo "$CRON_TIME $BACKUP_CMD >> $LOGFILE_APP 2>&1" | crontab -
126 | fi
127 |
128 | # Start crond if it's not running
129 | if ! pgrep crond > /dev/null 2>&1; then
130 | /usr/sbin/crond -L "$LOGFILE_CRON"
131 | fi
132 | }
133 |
134 | # Run backup in manual mode and exit
135 | manual_mode() {
136 | info "Running in manual mode."
137 | $BACKUP_CMD
138 | cat "$LOGFILE_APP"
139 | exit 0
140 | }
141 |
142 | ### Main ###
143 |
144 | # Init only when run as root because of permissions
145 | if [ "$(id -u)" -eq 0 ]; then
146 | init_folders
147 | adjust_permissions
148 |
149 | info "Container started"
150 | info "Running vaultwarden-backup version $VW_BACKUP_VERSION"
151 | info "Log level set to $LOG_LEVEL"
152 | debug "Environment Variables:\n$(env | sort)"
153 |
154 | if [ "$1" = "manual" ]; then manual_mode; fi
155 | if [ "$BACKUP_ON_STARTUP" = true ]; then
156 | info "Creating first backup on startup."
157 | $BACKUP_CMD
158 | fi
159 |
160 | init_cron
161 | fi
162 |
163 | # Restart script as desired user
164 | if [ "$(id -u)" -ne "$UID" ]; then
165 | debug "Restarting $(basename "$0") as $UID:$GID"
166 | exec su-exec "$UID:$GID" "$0" "$@"
167 | fi
168 |
169 | # Include cron.log in debug mode
170 | if [ "$LOG_LEVEL_NUMBER" -eq 7 ]; then
171 | tail -f -n +1 "$LOGFILE_APP" "$LOGFILE_CRON"
172 | fi
173 |
174 | tail -f -n +1 "$LOGFILE_APP"
175 |
--------------------------------------------------------------------------------
/src/usr/local/bin/healthcheck.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # shellcheck disable=SC1091
4 |
5 | . /opt/scripts/set-env.sh
6 |
7 | if [ ! -f "$HEALTHCHECK_FILE" ]; then
8 | printf 0 > "$HEALTHCHECK_FILE"
9 | fi
10 |
11 | exit "$(cat "$HEALTHCHECK_FILE")"
12 |
--------------------------------------------------------------------------------