scheduling brainstorm/feature-request: battery-level condition (rather than ac-power condition) #419

Closed
opened 1 month ago by jzacsh · 3 comments
jzacsh commented 1 month ago

What I'm trying to do and why

  • What:
  • Why: my battery is good enough (thinkpad x280) that my laptop is basically not awake if it's plugged into charger, therefore current sample systemd file would never schedule a backup. What I mean is, my current usage looks like this:
    1. unplug laptop, then open the lid!
    2. use laptop: sit wherever I want for 4-8 hours
    3. stop working, shut the lid, plug in the laptop

As you can see step ii is the only chance for backups to occur automatically, but

Expected behavior: docs feature request

I realize this isn't a bug/feature-request for borgmatic - it's more a feature request for the docs - specifically these wonderful sample files.

Other notes / implementation ideas

I'm guessing I'm not the only one who has similar usage patterns and found borgmatic excellent to get started with. So I'm hoping this can be a bug to keep track of ideas untli something solid comes along.

If I'm understanding the systemd docs right, there's really nothing more granular than ConditionACPower=true (ie: there's no ConditionPowerReserve=0.6 or anything). So I think this might become slightly more complicated as it'd have to be logic in borgmatic (or a script) rather than systemd files.

Environment

borgmatic version:

Use borgmatic --version

1.5.13

Fwiw, I'm not running as root - I've tweaked the systemd samples a bit because I'm only backing up my user files. Here's what I have in case it's useful to anyone (that took a bit of figuring out - so I'm happy to add a "user" sample to the repo if anyone wants that).

borgmatic installation method: pip3

Borg version: 1.1.9

operating system and version: debian buster 10.9

#### What I'm trying to do and why - **What**: - continue scheduling via systemd - see [this particular line of borgmatic.service sample](https://github.com/witten/borgmatic/blob/88cb49dcc4a858ce26a367673dbabf754037961b/sample/systemd/borgmatic.service#L5) - Automatically backup a **laptop _even_ if away from power** - perhaps when battery level is above X% (e.g. 60%). - **Why**: my battery is good enough (thinkpad x280) that my laptop is basically _not awake_ if it's plugged into charger, therefore current sample systemd file would never schedule a backup. What I mean is, my current usage looks like this: 1. unplug laptop, **then open the lid!** 1. _use_ laptop: sit wherever I want for 4-8 hours 1. stop working, **shut the lid**, plug in the laptop As you can see step `ii` is the only chance for backups to occur automatically, but #### Expected behavior: docs feature request I realize this isn't a bug/feature-request for borgmatic - it's more a feature request for the docs - specifically [these wonderful sample files](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#systemd). #### Other notes / implementation ideas I'm guessing I'm not the only one who has similar usage patterns _and_ found borgmatic excellent to get started with. So I'm hoping this can be a bug to keep track of ideas untli something solid comes along. If I'm understanding the systemd docs right, there's really nothing more granular than `ConditionACPower=true` (ie: there's no `ConditionPowerReserve=0.6` or anything). So I think this might become slightly more complicated as it'd have to be logic in borgmatic (or a script) rather than systemd files. #### Environment **borgmatic version:** > Use `borgmatic --version` 1.5.13 Fwiw, I'm _not_ running as root - I've tweaked the systemd samples a bit because I'm only backing up my user files. [Here's what I have](https://github.com/jzacsh/dotfiles/blob/27290b5fe2bf3528fdecba1f841bec951af4aeaa/.host/src/host.wajinru/borgmatic.service) in case it's useful to anyone (that took a bit of figuring out - so I'm happy to add a "user" sample to the repo if anyone wants that). **borgmatic installation method:** pip3 **Borg version:** 1.1.9 **operating system and version:** debian buster 10.9

Hi @jzacsh ,
you can use a command line tool which provides you the battery status and use it in a script and as pre-backup hook. The script would exit with code 75 if the battery level is too low so that borgmatic silently skips the backup.

You can find some options for checking the battery here https://www.cyberciti.biz/faq/linux-laptop-battery-status-temperature/

Hi @jzacsh , you can use a command line tool which provides you the battery status and use it in a script and as pre-backup hook. The script would exit with code 75 if the battery level is too low so that borgmatic silently skips the backup. You can find some options for checking the battery here https://www.cyberciti.biz/faq/linux-laptop-battery-status-temperature/
Poster

ah, indeed that works prefectly, thanks!

for anyone else looking for a quick answer, here's exactly what i did that works well:

and here's some sample output of what it looks like with systemd
# context: i'm running as a _user_ unit, not system backup: https://github.com/jzacsh/dotfiles/blob/27290b5fe2bf3528fdecba1f841bec951af4aeaa/.host/src/host.wajinru/borgmatic.service

$ systemctl --user start borgmatic.service # battery currently at 20% and discharging
# snipped - but failed; see next output


$ journalctl --user-unit borgmatic.service --pager-end
May 11 10:10:39 myhostname systemd[1150]: Starting borgmatic backup...
May 11 10:11:40 myhostname borgmatic[21141]: INFO /home/myusername/.config/borgmatic/config.yaml: Running 2 commands for pre-backup hook
May 11 10:11:40 myhostname systemd-inhibit[21129]: discharging and below threshold of 82% (currently: 78%)
May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running pre hook
May 11 10:11:40 myhostname systemd-inhibit[21129]: Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1.
May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running configuration file
May 11 10:11:40 myhostname borgmatic[21141]: WARNING discharging and below threshold of 82% (currently: 78%)
May 11 10:11:40 myhostname systemd-inhibit[21129]: summary:
May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running configuration file
May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running pre hook
May 11 10:11:40 myhostname systemd-inhibit[21129]: discharging and below threshold of 82% (currently: 78%)
May 11 10:11:40 myhostname systemd-inhibit[21129]: Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1.
May 11 10:11:40 myhostname systemd-inhibit[21129]: Need some help? https://torsion.org/borgmatic/#issues
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running pre hook
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1.
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running configuration file
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL summary:
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running configuration file
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running pre hook
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL discharging and below threshold of 82% (currently: 78%)
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1.
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL
May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Need some help? https://torsion.org/borgmatic/#issues
May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.local/bin/borgmatic failed with exit status 1.
May 11 10:11:40 myhostname systemd[1150]: borgmatic.service: Main process exited, code=exited, status=1/FAILURE
May 11 10:11:40 myhostname systemd[1150]: borgmatic.service: Failed with result 'exit-code'.
May 11 10:11:40 myhostname systemd[1150]: Failed to start borgmatic backup.
ah, indeed that works prefectly, thanks! for anyone else looking for a quick answer, here's exactly what i did that works well: - super sipmle script: https://github.com/jzacsh/bin/commit/c758a802fb4a3f76fe56896f64fb962bc7c6475f - one-line borgmatic config change: https://github.com/jzacsh/dotfiles/commit/d6733bcbacb7a67f13c6d591851e06b9acb7217c <details> <summary>and here's some sample output of what it looks like with systemd</summary> ``` # context: i'm running as a _user_ unit, not system backup: https://github.com/jzacsh/dotfiles/blob/27290b5fe2bf3528fdecba1f841bec951af4aeaa/.host/src/host.wajinru/borgmatic.service $ systemctl --user start borgmatic.service # battery currently at 20% and discharging # snipped - but failed; see next output $ journalctl --user-unit borgmatic.service --pager-end May 11 10:10:39 myhostname systemd[1150]: Starting borgmatic backup... May 11 10:11:40 myhostname borgmatic[21141]: INFO /home/myusername/.config/borgmatic/config.yaml: Running 2 commands for pre-backup hook May 11 10:11:40 myhostname systemd-inhibit[21129]: discharging and below threshold of 82% (currently: 78%) May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running pre hook May 11 10:11:40 myhostname systemd-inhibit[21129]: Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1. May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running configuration file May 11 10:11:40 myhostname borgmatic[21141]: WARNING discharging and below threshold of 82% (currently: 78%) May 11 10:11:40 myhostname systemd-inhibit[21129]: summary: May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running configuration file May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.config/borgmatic/config.yaml: Error running pre hook May 11 10:11:40 myhostname systemd-inhibit[21129]: discharging and below threshold of 82% (currently: 78%) May 11 10:11:40 myhostname systemd-inhibit[21129]: Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1. May 11 10:11:40 myhostname systemd-inhibit[21129]: Need some help? https://torsion.org/borgmatic/#issues May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running pre hook May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1. May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running configuration file May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL summary: May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running configuration file May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL /home/myusername/.config/borgmatic/config.yaml: Error running pre hook May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL discharging and below threshold of 82% (currently: 78%) May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Command '/home/myusername/bin/share/is_power_sufficient 82' returned non-zero exit status 1. May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL May 11 10:11:40 myhostname borgmatic[21141]: CRITICAL Need some help? https://torsion.org/borgmatic/#issues May 11 10:11:40 myhostname systemd-inhibit[21129]: /home/myusername/.local/bin/borgmatic failed with exit status 1. May 11 10:11:40 myhostname systemd[1150]: borgmatic.service: Main process exited, code=exited, status=1/FAILURE May 11 10:11:40 myhostname systemd[1150]: borgmatic.service: Failed with result 'exit-code'. May 11 10:11:40 myhostname systemd[1150]: Failed to start borgmatic backup. ``` </details>
Owner

Awesome.. creative solution! I've taken a stab at documenting (or at least mentioning) the use case here: https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/

I've also added a comment to the systemd service file about ConditionACPower=true.

Thanks for bringing this up!

Awesome.. creative solution! I've taken a stab at documenting (or at least mentioning) the use case here: https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/ I've also added a comment to the systemd service file about `ConditionACPower=true`. Thanks for bringing this up!
witten closed this issue 1 week ago
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.