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
Try something like if file config.xml & directory data, snapshots, keys, locks exist than backup
I checked my code and I detect for config.xml. Whether you should init or throw an error depends on what you’re doing.
The file is called config
, not config.xml
.
Good point. Autocomplete suggested it and I went with it because I’m lazy typing on my phone.
akrabu
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.
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.
There is not a proper way yet, but this workaround is one way:
#!/bin/bash
export RESTIC_REPOSITORY=sftp:restic:/lan
if restic cat config >/dev/null 2>&1; then
echo initialized
else
echo 'not initialized'
fi
1 Like