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

Missing support for multiple users on the same host / same lock-file used by user and root #1122

Closed
mat-m opened this issue Dec 6, 2020 · 11 comments · Fixed by #1697
Closed
Labels
Bug Medium Scheduling cron, anacron etc.

Comments

@mat-m
Copy link

mat-m commented Dec 6, 2020

Hello

I had an issue where snapshots were not taken.
I decided to run in CLI with /usr/bin/backintime backup --debug and got:

DEBUG: [common/snapshots.py:1751 Snapshots.flockExclusive] Set flock /tmp/backintime.lock
Traceback (most recent call last):
  File "/usr/share/backintime/common/backintime.py", line 1165, in <module>
    startApp()
  File "/usr/share/backintime/common/backintime.py", line 517, in startApp
    args.func(args)
  File "/usr/share/backintime/common/backintime.py", line 739, in backup
    ret = takeSnapshot(cfg, force)
  File "/usr/share/backintime/common/backintime.py", line 94, in takeSnapshot
    ret = snapshots.Snapshots(cfg).backup(force)
  File "/usr/share/backintime/common/snapshots.py", line 633, in backup
    self.flockExclusive()
  File "/usr/share/backintime/common/snapshots.py", line 1752, in flockExclusive
    self.flock = open(self.GLOBAL_FLOCK, 'w')
PermissionError: [Errno 13] Permission denied: '/tmp/backintime.lock'

Actually, the lock belongs to the other user, which also has a @reboot job, but starts before me.

Flock should hold user & BIT profile name, IMO.

@buhtz
Copy link
Member

buhtz commented Dec 7, 2020

Can you provide an ls -l for /tmp/backintime.lock please.

@mat-m
Copy link
Author

mat-m commented Dec 20, 2020

Current one for me:

➜ ls -l  /tmp/backintime.lock 
-rw-rw-rw- 1 mm mm 0 déc.  20 01:35 /tmp/backintime.lock

@gitraphha
Copy link

gitraphha commented Sep 1, 2021

Hello,
this behaviour occurs on my machine as well, so I'd like to contribute some details of what happens when in my case.

BIT version: 1.2.1 (running on Kubuntu 21.04)

If a regular user "reguser" runs a backup job (or their job is automatically started by cron), the following lock file is created when the backup job starts (i.e. not already at (manual) program startup).

ls -l /tmp/backintime*
-rw-rw-rw- 1 reguser reguser 0 Sep  1 16:11 /tmp/backintime.lock

The problem then is - this lock file is not deleted on completion of the backup job.

So if some time later root runs a backup job (again possibly their job is automatically started by cron, same behaviour) it will fail and I get the above mentioned error:
PermissionError: [Errno 13] Permission denied: '/tmp/backintime.lock'
If I manually delete this file, root's or my reguser's backup job (manual or started by cron) runs without problems.

So this seems to be exactly this problematic multi-user setting. For me it would be fine if the second user can't start their job before the first user's job is finished (as selected under "settings-options-run only one snapshot at a time", which is activated in my case for both reguser and root). However, if this first job is finished, the lock file should be removed, shouldn't it?

Thanks for looking into this...
Raph

@gitraphha
Copy link

some more information about starting and running backups as reguser and root, details see attached file
backintime_steps.log

tl;dr:

  • reguser can run backups after root ran theirs (backintime.lock persists all the time and is owned by root)
  • root can NOT run backups after reguser ran theirs (backintime.lock persists all the time and is owned by reguser)

@buhtz
Copy link
Member

buhtz commented Sep 25, 2022

There is a new forming maintaining team and we do review all issues. Is this problem still relevant for you or did you find a solution?

@gitraphha Thanks for your summary about the problem.

Tag: Feedback, Bug, Scheduling, Medium

@mat-m
Copy link
Author

mat-m commented Oct 1, 2022

@buhtzz Glad a new team is coming ! Thanks so much for this !
I worked it around by using root everywhere (not ideal, though). Also, maybe the lock name is too generic to handle mutli-users or multi-targets. I actually don't know what you want to lock. In my opinion, the lock should be on the target dir.

@emtiu emtiu added Scheduling cron, anacron etc. Medium Bug labels Oct 8, 2022
@emtiu
Copy link
Member

emtiu commented Oct 8, 2022

Okay, so the cause of the bug seems to be that in certain situations, /tmp/backintime.lock is not deleted for some reason.

More generally, it's worth a look at why that logfile exists in the first place, and if it could be changed to a per-user lock.

@fallingrock
Copy link
Contributor

I'm seeing the same thing.

I've got two backup's scheduled ... one for my home directory that runs hourly (running as me), and one for the entire system (running as root).

The root backup frequently doesn't run because that lock file exists owned by my own profile.

@buhtz buhtz changed the title Missing support for multiple users on the same host Missing support for multiple users on the same host / same lock-file used by user and root Jun 1, 2023
@gitraphha
Copy link

There is a new forming maintaining team and we do review all issues. Is this problem still relevant for you or did you find a solution?

wonderful, thank you for your efforts!

I didn't check again lately, because I have this workaround running which solves the problem (still just a workaround)

this is part of my ~/config/backintime/user-callback #!/bin/bash script

profile_id="$1"
profile_name="$2"
reason="$3"
errorcode="$4"

case $reason in
    2) #Backup process ends.
      LCKFILE='/tmp/backintime.lock'
      if [[ -f  $LCKFILE && -O "$LCKFILE" ]]; then
        echo "workaround for leftover file $LCKFILE -> delete" | tee -a "$LOGFILE"
        ls -l "$LCKFILE" | tee -a "$LOGFILE"
        rm -v $LCKFILE 2>&1 | tee -a "$LOGFILE"
     fi
    ;;

the most confusing thing about this bug(?) is that the reguser can cope with root's leftover lockfile but not the other way round

Have a nice day everybody!

@buhtz
Copy link
Member

buhtz commented Apr 17, 2024

Accidentally discovered this "old" issue here.
Might be the same problem as described in #1676. In that issue I propose a solution to the problem but waiting for feedback from more experienced users/developers.

@buhtz
Copy link
Member

buhtz commented Apr 21, 2024

I opened PR #1697. Would be glad if you could give it a try and test it in your environment. Let me know if you have further questions or if I can be of assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Medium Scheduling cron, anacron etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants