Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository is already locked, forget cmd fails but systemd service is marked successful #88

Open
varac opened this issue Oct 19, 2022 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@varac
Copy link
Contributor

varac commented Oct 19, 2022

I often get this issue that the repository is locked, and the forget cmd fails:

backup-all.sh[577930]: + [[ 0 -eq 0 ]]
backup-all.sh[578466]: + systemd-cat -t all
backup-all.sh[578467]: ++ date -u '+%Y-%m-%d %H:%M:%S'
backup-all.sh[578465]: + echo '2022-10-19 08:19:03 OK'
all[578466]: 2022-10-19 08:19:03 OK
backup-all.sh[578468]: + /usr/local/bin/restic forget --path / --keep-last 10 --prune
backup-all.sh[578469]: + systemd-cat -t all
all[578469]: unable to create lock in backend: repository is already locked by PID 294851 on sancho.varac.net by root (UID 0, GID 0)
all[578469]: lock was created at 2022-10-18 00:00:05 (34h19m6.088127533s ago)
all[578469]: storage ID 361f61fc
all[578469]: the `unlock` command can be used to remove stale locks
backup-all.sh[577930]: + [[ 1 -eq 0 ]]
backup-all.sh[578486]: + systemd-cat -t all
backup-all.sh[578487]: ++ date -u '+%Y-%m-%d %H:%M:%S'
backup-all.sh[578485]: + echo '2022-10-19 08:19:11 ERROR'
all[578486]: 2022-10-19 08:19:11 ERROR
backup-all.sh[577930]: + rm -f /var/run/restic_backup_all.pid
backup-all.sh[577930]: + exit
systemd[1]: restic-all.service: Deactivated successfully.
systemd[1]: Finished Backup all using restic.

However, in this case the script ends with an exit code of 0 and therefore the systemd service is marked as successful, which makes it very hard to notice when the forget fails:

❯ systemctl status restic-all
○ restic-all.service - Backup all using restic
     Loaded: loaded (/lib/systemd/system/restic-all.service; static)
    Drop-In: /etc/systemd/system/restic-all.service.d
             └─env.conf, untethered.conf
     Active: inactive (dead) since Wed 2022-10-19 10:19:11 CEST; 36min ago
TriggeredBy: ● restic-all.timer
   Main PID: 577930 (code=exited, status=0/SUCCESS)
        CPU: 14min 4.131s

It can be reproduced manually as well:

root@sancho:~# /usr/local/bin/backup-all.sh 
+ [[ -z '' ]]
+ MODE_TAG='--tag manual'
+ /usr/local/bin/restic backup / --tag manual --exclude-caches --exclude-file /etc/backup.exclude --exclude-if-present .exclude_from_backup
+ systemd-cat -t all
+ [[ 0 -eq 0 ]]
+ systemd-cat -t all
++ date -u '+%Y-%m-%d %H:%M:%S'
+ echo '2022-10-19 09:04:12 OK'
+ /usr/local/bin/restic forget --path / --keep-last 10 --prune
+ systemd-cat -t all
+ [[ 1 -eq 0 ]]
+ systemd-cat -t all
++ date -u '+%Y-%m-%d %H:%M:%S'
+ echo '2022-10-19 09:04:14 ERROR'
+ rm -f /var/run/restic_backup_all.pid
+ exit

root@sancho:~# echo $?
0
@DO1JLR
Copy link
Member

DO1JLR commented Mar 22, 2023

Yes, I am currently not entirely happy with the behaviour of the script and have been planning to revise it for some time. Unfortunately, I haven't got around to it yet.

If you feel like taking a closer look, I would of course appreciate it.

@DO1JLR DO1JLR added the help wanted Extra attention is needed label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Development

No branches or pull requests

2 participants