Skip to content

Commit

Permalink
Merge pull request #102 from djmaze/skip-repository-check-when-unlocking
Browse files Browse the repository at this point in the history
Skip repository check when unlock command is given
  • Loading branch information
djmaze authored Sep 20, 2021
2 parents 116c818 + 5350cf6 commit 21f0dce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Run automatic [restic](https://restic.github.io/) backups via a Docker container
* support for tags, exclude definitions, and all other optional restic options
* automatic forgetting of old backups
* prune backups on a schedule
* remove a stale repository lock
* can be used as a (global) Docker swarm service in order to backup every cluster node
* multi-arch: the image `mazzolino/restic` runs on `amd64` as well as `armv7` (for now)

Expand Down Expand Up @@ -58,6 +59,8 @@ E.g.

docker-compose run --rm app snapshots

When given the `unlock` command, the repository check will be skipped (because it will fail on a locked repository either way).

## Configuration options

*Note: `BACKUP_CRON`, `PRUNE_CRON` and `CHECK_CRON` are mutually exclusive.*
Expand Down
28 changes: 16 additions & 12 deletions entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ if [[ -d "$SSH_CONFIG_PATH" ]]; then
chmod -R u+rwX,go-rwx /root/.ssh
fi

echo "Checking configured repository '${RESTIC_REPOSITORY}' ..."
if restic cat config > /dev/null; then
echo "Repository found."
else
echo "Could not access the configured repository. Trying to initialize (in case it has not been initialized yet) ..."
if restic init; then
echo "Repository successfully initialized."
command="${1-}"

if [[ "$command" != "unlock" ]]; then
echo "Checking configured repository '${RESTIC_REPOSITORY}' ..."
if restic cat config > /dev/null; then
echo "Repository found."
else
if [ "${SKIP_INIT_CHECK:-}" == "true" ]; then
echo "Initialization failed. Ignoring errors because SKIP_INIT_CHECK is set in your configuration."
echo "Could not access the configured repository. Trying to initialize (in case it has not been initialized yet) ..."
if restic init; then
echo "Repository successfully initialized."
else
echo "Initialization failed. Please see error messages above and check your configuration. Exiting."
exit 1
if [ "${SKIP_INIT_CHECK:-}" == "true" ]; then
echo "Initialization failed. Ignoring errors because SKIP_INIT_CHECK is set in your configuration."
else
echo "Initialization failed. Please see error messages above and check your configuration. Exiting."
exit 1
fi
fi
fi
echo -e "\n"
fi
echo -e "\n"

if [[ $# -gt 0 ]]; then
exec restic "$@"
Expand Down

0 comments on commit 21f0dce

Please sign in to comment.