Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Provide multiple repositories via env variables #183

Open
marco-calautti opened this issue Feb 4, 2024 · 8 comments
Open

Provide multiple repositories via env variables #183

marco-calautti opened this issue Feb 4, 2024 · 8 comments

Comments

@marco-calautti
Copy link

It would be very convenient to pass to the container a list of repositories, rather than a single one. So that the same operations can be execute for multiple repositories in the same session. At the moment, one has to run instances of the container with almost identical configurations, to backup to two or more repositories.

@ThomDietrich
Copy link
Contributor

... plus it would be great to run multiple syncs in sequence. Currently this can only be achieved by careful definition of the cron expressions.

I support this request

@djmaze
Copy link
Owner

djmaze commented Feb 18, 2024

Do I get this right, you want to backup the same data to multiple repositories?

@marco-calautti
Copy link
Author

Exactly

@ThomDietrich
Copy link
Contributor

Then I got it wrong 😄
I think it would be a worthy addition to be able to define multiple jobs in general. The use case would be to easily configure something that runs multiple backup jobs in sequence, e.g. at 3:00 am on workdays.

@smainz
Copy link
Contributor

smainz commented Feb 27, 2024

I have a derived image which includes the script push-to-mirror.sh (You can also mount it into the container)

#!/bin/bash

# If mirror repository and password are set on the command line, use these, otherwise rely on the environment

if [ -n "$1" ]; then
    RESTIC_MIRROR_REPOSITORY=$1
    if [ -n "$2" ]; then
        RESTIC_MIRROR_PASSWORD=$2
    fi
fi

if [ -z "$RESTIC_MIRROR_REPOSITORY" ] || [ -z "$RESTIC_MIRROR_PASSWORD" ]; then
    echo "Usage $0 <RESTIC_MIRROR_REPOSITORY> <RESTIC_MIRROR_PASSWORD>"
    echo ""
    echo "    if RESTIC_MIRROR_REPOSITORY is not given the environment variable RESTIC_MIRROR_REPOSITORY is used."
    echo "    if RESTIC_MIRROR_PASSWORD is not given the environment variable RESTIC_MIRROR_PASSWORD is used."
    echo ""
    exit 255
fi

# Try to initialize mirror repository
if RESTIC_PASSWORD=${RESTIC_MIRROR_PASSWORD} restic --repo ${RESTIC_MIRROR_REPOSITORY} cat config  > /dev/null; then
    echo "Mirror Repository exists, password is correct"
else
    echo "Trying to initialize mirror repository"
    RESTIC_FROM_PASSWORD=${RESTIC_PASSWORD} \
    RESTIC_PASSWORD=${RESTIC_MIRROR_PASSWORD} \
    restic --repo ${RESTIC_MIRROR_REPOSITORY} init --from-repo ${RESTIC_REPOSITORY} --copy-chunker-params
fi


echo "Copy local repository to mirror repository"
RESTIC_FROM_PASSWORD=${RESTIC_PASSWORD} \
RESTIC_PASSWORD=${RESTIC_MIRROR_PASSWORD} \
restic --repo ${RESTIC_MIRROR_REPOSITORY} copy --from-repo ${RESTIC_REPOSITORY}

echo  "Clean up mirror repository (purge old files)"
RESTIC_PASSWORD=${RESTIC_MIRROR_PASSWORD} \
restic --repo ${RESTIC_MIRROR_REPOSITORY} forget --prune ${RESTIC_MIRROR_FORGET_ARGS}

echo  "Unlock mirror in case ssh connection failed in above command"
RESTIC_PASSWORD=${RESTIC_MIRROR_PASSWORD} \
restic --repo ${RESTIC_MIRROR_REPOSITORY} unlock

RESTIC_MIRROR_REPOSITORY and RESTIC_MIRROR_PASSWORD need to be set as env vars like the ordinary ones.

@djmaze
Copy link
Owner

djmaze commented Feb 27, 2024

Well, I think the configuration via env variables is already complicated enough. I am unsure if it is a good idea to add even one
more layer of variables. The thing that comes to mind would be adding numbers to all variables. Like RESTIC_REPOSITORY_1, RESTIC_PASSWORD_1, RESTIC_REPOSITORY_2 and so on. But that would be an optional way to configure this. The old way should still always be available for backwards compatibility reasons.

@ThomDietrich
Copy link
Contributor

@djmaze I personally think that would be a very valuable addition and I like your suggestion. Do you see yourself implementing those or are you limited to accept PRs? :)

@djmaze
Copy link
Owner

djmaze commented Feb 28, 2024

Tbh I am not really incentivized as I'd rather cope with multiple containers with different schedules rather than increasing the complexity of the service. That said, if someone wants to implement this in a clean manner, then I would be open to accept it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants