restic icon indicating copy to clipboard operation
restic copied to clipboard

restic init option to ignore if already exists

Open yene opened this issue 4 years ago • 5 comments

Dear restic,

thank you for creating the useful tool.

During writing of a backup script I was unable to find an option to suppress the error message: "Fatal: create key in repository at ... failed: repository master key and config already initialized"

Some inspiration from kubernetes:

restic init --ignore-if-exists

or helm:

restic backup --init

priority: low version: restic 0.13.0 compiled with go1.18 on darwin/amd64

yene avatar Mar 30 '22 07:03 yene

What is your use case exactly? Would a command to check whether a repository already exist be more useful for your use case?

MichaelEischer avatar Apr 03 '22 18:04 MichaelEischer

Not OP, but such a command, to check this natively, would indeed be helpful. F.e. currently our detection if a repo was initialized, looks like this:

if ! run_restic snapshots &>/dev/null; then log something if ! run_restic init; then log something exit 2 fi fi

Works great, but is more of a workaround.

iheartski avatar Apr 04 '22 08:04 iheartski

ah thanks, I am lazy and just do restic init || true

yene avatar Apr 04 '22 18:04 yene

@iheartski run_restic cat config would probably be a lot faster to check whether a repository exists.

MichaelEischer avatar Apr 04 '22 19:04 MichaelEischer

In my non scientific test, i see practically no difference in speed between cat config and snapshots. Checked for a repo with 7 snapshots, and one with 1300+. Runtimes are within .1 seconds usually. No WAN connection involved, SFTP storage backend.

iheartski avatar Apr 05 '22 08:04 iheartski