Test for repository existence


#1

Is there a way of verifying a repository’s existence - that can be tested for via a Bash script? So I can write something like

#!/bin/bash
#<assume repo & pass defined in environment>
if [[ ! restic repo-exists ]] then;
restic init
fi
…continue with backup process


#2

Try something like if file config.xml & directory data, snapshots, keys, locks exist than backup


#3

I checked my code and I detect for config.xml. Whether you should init or throw an error depends on what you’re doing.


#4

The file is called config, not config.xml.


#5

Good point. Autocomplete suggested it and I went with it because I’m lazy typing on my phone.


#6

I do this for Backblaze (in a startup script):

sleep 30

if [ $( ping -c 3 backblaze.com | grep icmp* | wc -l ) -eq 0 ]
then
ECHO
ECHO “Backblaze is unreachable. Quitting.”
ECHO
exit 0
fi

Not quite the same as testing for the exact repo’s existence, but testing for the repo’s provider serves my purposes.


#7

You could do that using:

if [[ ! -f "/path/to/your/repo/config" ]] ; then
  restic init
fi

So if the config file is there it will do nothing.