borgbackup / borg

Deduplicating archiver with compression and authenticated encryption.
https://www.borgbackup.org/
Other
10.73k stars 734 forks source link

Running command in hook on behalf of another user? #8147

Closed ostasevych closed 3 months ago

ostasevych commented 3 months ago

Hi! I use borgmatic for backing up certain apps, which I need to stop on behalf of the www-data user before and start after running the backup.

I've added a couple of hooks:

before_backup:
  - echo "`date` - Starting backup"`
  - apprise -c /etc/apprise.yaml -t "⚙ PREPARING" --tag=test
  - sudo - u www-data php /var/www/mycloud/myapp config:system:set maintenance --value=true

after_backup:
  - echo "`date` - Finished backup"`
  - apprise -c /etc/apprise.yaml -t "✅ DONE" --tag=test
  - sudo -u www-data php /var/www/mycloud/myapp config:system:set maintenance --value=false

When executed borgmatic reports that:

Mar 05 07:22:59 my.local borgmatic[1105519]: CRITICAL sudo: no valid sudoers sources found, quitting
Mar 05 07:22:59 my.local borgmatic[1105519]: CRITICAL sudo: error initializing audit plugin sudoers_audit
Mar 05 07:22:59 my.local borgmatic[1105519]: CRITICAL Command 'sudo -u www-data php /var/www/mycloud/myapp config:system:set maintenance --value=false' returned non-zero exit status 1.

Is it possible to use sudo in hooks somehow or what to use?

UPD:

The only workaround, which I've found is to replace the string variable manually:

before_backup:
    - /usr/local/bin/app-maint-on

where app-maint-on:

#!/bin/bash
# Enable maintenance mode in app
printf "1,$ s/'maintenance' => false/'maintenance' => true/g\nw! /var/www/mycloud/config/config.php\nq!" | ex - /var//www/nextcloud/config/config.php

But that is like a workaround, which doesn't allow me to process the exit code from the execution of the app command.

infectormp commented 3 months ago

The right place for this question is here https://projects.torsion.org/borgmatic-collective/borgmatic/issues

ostasevych commented 3 months ago

The right place for this question is here https://projects.torsion.org/borgmatic-collective/borgmatic/issues

It is almost not possible to submit issues there :( image

infectormp commented 3 months ago

Are you experiencing an issue with borgmatic? Or do you have an idea for a feature enhancement? Head on over to our issue tracker. In order to create a new issue or add a comment, you'll need to register first. If you prefer to use an existing GitHub account, you can skip account creation and login directly.