backrest icon indicating copy to clipboard operation
backrest copied to clipboard

Add condition for certain network available to backup plan

Open silmaril42 opened this issue 9 months ago • 1 comments

I am using backrest with several PCs in my local network. The repo is a restic restserver instance in this LAN, which is not accessible from the internet.

Some of these PCs are laptops, that only have access to the repo while they are connected to either a certain Wifi or a certain ethernet connection.

It seems backrest is oblivious of changing network availability. When a backup job is run without connection to the necessary network, we get an error message that may be misleading:

error: failed to get snapshots for plan: ... 
Fatal: unable to open config file: Head "http://:***@..."  dial tcp: lookup ... server misbehaving
Is there a repository at the following location?

First of all I would prefer to see some concise error message like "Cannot connect to repo server ...". This might be followed by the DNS errors to facilitate debugging, but in many cases the problem won't be DNS, it will simply be no connection to the network of the repo.

And then it would be great if we could configure plans to only run when certain network conditions are met. If a job is due and the conditions are not met, backrest should re-check those conditions with a configurable frequency (eg. every 30 minutes) and ensure the job runs as soon as the device is in the network again. (Or maybe there is some hook for network status changes? That would be ideal.)

I am unsure about how those conditions could be implemented and could think of several options like

  • "We need to be connected to a certain wifi" (which we could get using iwconfig on linux systems).
  • "We need to be connected to a certain network (eg. IPv4 192.168.123.0/24 or IPv6 2001:9e5:cd3f:ebe0:1202:1234:4567:89ab/64).
  • "We need to be able to ping a certain host." (eg. the restserver host).

I think it should be possible to configure several such conditions and they should be evaluated with an OR between them (I don't see practical use cases for AND here).

silmaril42 avatar Mar 22 '25 12:03 silmaril42

Hey -- I've actually given a bit of thought to this scenario, though there isn't a built in check for this it's a case I'm thinking is handled well by scripting.

Would something similar to https://garethgeorge.github.io/backrest/cookbooks/command-hook-examples#internet-connectivity-check work well for you? e.g.

if ping -q -c 1 -W 1 google.com >/dev/null; then
  echo "Internet connection is up"
  exit 0
else
  echo "Internet connection is down"
  exit 1
fi

in conjunction with the CONDITION_SNAPSHOT_START hook with the policy ON_ERROR_CANCEL will cancel a backup attempt gracefully if its detected that it would fail because the network is unavailable.

garethgeorge avatar Mar 28 '25 00:03 garethgeorge