Open jocelynthode opened 1 year ago
Looking at my restic setup, the restic systemd service does wait on network-online.target
, but that is not always enough: network-online.target
does not guarantee that my remote backup locations are reachable.
This is problematic as the backup is by default attempted on a "daily" timer. In practice, this means "at midnight" and "on startup, if we missed the midnight run". But if the machine is never on at midnight, and backups are attempted at startup as soon as network-online.target
is reached (and possibly before my backup repository is reachable), then backups never complete.
I am not familiar enough with systemd timers - would there be a way to express "run to completion once a day, but in case of failures, retry every hour"? And would that be a reasonable default?
It turns out since 2019, oneshot services support Restart=on-failure
. This does not solve the title of the issue here, but it's a decent enough workaround for my needs. I just add:
systemd.services."restic-backups-to-GCS" ={
serviceConfig = {
Restart = "on-failure";
RestartSec = "60s";
};
unitConfig = {
StartLimitIntervalSec = 3600;
StartLimitBurst = 15;
};
};
This means the restic unit will start at some point after network-online.target is reached and it may still fail for any number of reasons, but it will now retry every minute for 15 minutes. This is enough for my main use-case of "laptop booted but is not connected to Wifi yet".
As an alternative workaround to @korfuri, the restic
service also has a backupPrepareCommand
option that you could abuse to do something like this:
backupPrepareCommand = ''
while ! /run/current-system/sw/bin/ping -c 1 1.0.0.1; do
echo "Waiting for internet connection..."
sleep 60
done
echo "Internet is up, let's upload ~raccoon memes~ some backups!"
'';
Describe the bug
When using
services.restic
with a remote repository such as a S3 repository. The service does not wait for the network to be ready. This causes issues when service starts on the boot due to for example aPersistent
parameterSteps To Reproduce
Steps to reproduce the behavior:
Use the following config:
Due to the Persistent settings the backup will be executed on boot if we missed the
onCalendar
dateExpected behavior
The service should wait for
network-online.target
to be able to resolve and contact the remote repositoryNotify maintainers
@thiagokokada @pennae
Metadata