Skip to content

Only run backups when battery is full #539

Description

@ktosiek

Is your feature request related to a problem? Please describe.
On a slow or metered connection backups can take most of the bandwidth.

Describe the solution you'd like
It should be possible to skip scheduled backups if the available connection is known to be metered, or even when it's not known to be unmetered. A running backup should be stopped if we lose a suitable connection.

Describe alternatives you've considered
The only alternative I know is enabling notifications and stopping the backup when I know I don't want it to run, which is not very handy.

Activity

  1. m3nu commented on Jul 1, 2020

    @m3nu
    Contributor

    The Wifi settings already attempt to solve this problem. Under Schedule > Networks > Allowed Networks. Select only "unmetered" networks to use for automatic backups.

    How would the feature suggested here be different and if so how would it be implemented?

  2. added
    status:ideaProposed feature, discuss if its useful
    status:duplicateAnother identical issue has been posted
    on Jul 1, 2020
  3. samuel-w commented on Jul 2, 2020

    @samuel-w
    Contributor

    But the button is not visible if you don't have Wifi, yet it is possible to have a metered wired connection.

  4. ktosiek commented on Jul 2, 2020

    @ktosiek
    ContributorAuthor

    I think that's only implemented for OSX.

    On Linux with NetworkManager you can mark connections (of any type, not just WiFi) as metered, and this is honoured by some applications. NetworkManager even tries to guess that status for active connections (for example tethering through Android is marked as "guessed as metered").

    The options I feel would make sense are:

    • Use any connection
    • Only use unmetered connections (which would be a good default, but needs a warning in the UI saying why scheduled backups are paused)
    • Use explicit WiFi whitelist (but what about Ethernet connections then? Are those listed too on OSX?)
  5. m3nu commented on Jul 2, 2020

    @m3nu
    Contributor

    Using NetworkManager to grab Wifi details on Linux came up before and would be a nice addition.

  6. added
    help wantedThis issue is available, comment if you want to fix it
    status:planningFor large features, plan it out before implementation
    and removed
    status:duplicateAnother identical issue has been posted
    status:ideaProposed feature, discuss if its useful
    on Jul 2, 2020
  7. ktosiek commented on Jul 2, 2020

    @ktosiek
    ContributorAuthor

    How does the networks list work on OS X? Is it just WiFi networks? Will backup run over cable when some WiFi network is selected from the list?

  8. samuel-w commented on Jul 2, 2020

    @samuel-w
    Contributor

    Communication with NetworkManager takes either another dependency https://pypi.org/project/python-networkmanager/ or DBus. Which one is prefered?

  9. m3nu commented on Jul 3, 2020

    @m3nu
    Contributor

    If DBus is not too hard to implement, I'd rather avoid more deps. Else mark it as Linux-only in setup.cfg.

    And before writing any code, feel free to summarize your planned implementation/changes.

  10. ktosiek commented on Jul 3, 2020

    @ktosiek
    ContributorAuthor

    I think we don't need python-networkmanager: the most interesting part for us is the SSID decoding function (NetworkManager provides raw SSIDs), and the library uses a different DBus implementation than Vorta already uses for notifications. And that's for enabling the WiFi block list, which I think is out of scope for this issue.

    For the UI I'd just add a "Don't run backup over metered networks", enabled by default, and visible only when NM is available.

    The actual implementation should have two parts:

    1. An additional check in BorgCreateThread.prepare
    2. Some way of stopping the backup if NM tells us we moved to a metered connection (for example, when user marks the current connection as metered). This should be possible without polling, by listening to DBus signals, but I'm not sure where something like that should live in the application code.
  11. ktosiek commented on Jul 8, 2020

    @ktosiek
    ContributorAuthor

    @m3nu do you think the approach described above is appropriate? I wonder if some additional UI that tells the user that the backup is not going to run and why would be needed, or can that be added later? I'm already thinking about other conditions, like being on battery power.

  12. m3nu commented on Jul 8, 2020

    @m3nu
    Contributor

    Yeah, this can work and it's nice to see how you guys are coming up with new ideas. Battery power is a nice option too and should be easy to implement on all OSs.

  13. samuel-w commented on Jul 21, 2020

    @samuel-w
    Contributor

    For the battery power, we can use psutil which is already a dependency, and a UI like

    [x] Run on battery power only when above [qspinbox] % charged

    and place it in the schedule page, only visible when there is a battery. To run only when on charger there would be a tooltip that says "Setting this to 100% will run scheduled backups only when on charger" on qspinbox

  14. ktosiek commented on Jul 23, 2020

    @ktosiek
    ContributorAuthor

    Is there some way to get notifications from psutil? It would be great to not just check the condition once, but actually be able to stop the backup when the conditions change.

    For networks it kind of happens by itself - changing the connection will probably make Borg timeout. But for battery we'd need to monitor the inputs somehow. Using something like UPower on Linux or UIKit on OSX can give us change notifications without polling, but I don't know if there's a library that abstracts over them.

  15. samuel-w commented on Jul 24, 2020

    @samuel-w
    Contributor

    Not that I know of, but there could be a loop to poll every second or so. I don't think its needed, since it complicates the code and isn't really relevant for the typical use-case of personal backups, which complete in a few minutes at most.

  16. ktosiek commented on Jul 24, 2020

    @ktosiek
    ContributorAuthor

    The backups being short is a good point, but they eat a lot of CPU. And I'm not sure if they are that short on HDDs, I've only tested on SSDs.
    Maybe a poll every few (even 30?) seconds, and stopping if 2 consecutive polls say the conditions aren't right anymore? This would make the whole thing more robust against accidental power cable disconnections. I know this is getting a bit complicated, but it might work pretty well. And with borg 1.2 running a checkpoint after first SIGINT, we wouldn't waste much of the compression/encryption and upload work.

    On the other hand, is there some OS-level "low power consumption" thing we can hook into on any OS? Something like Android's battery saving? It might not be as flexible, but would be a great default.

  17. samuel-w commented on Sep 4, 2020

    @samuel-w
    Contributor

    macOS does have a power saving mode https://support.apple.com/en-us/HT202824 but I have no idea what the API is.
    For Linux there are so many ways to have power saving mode (TLP, pm-utils, slimbook, others) that it will be too hard to cover all cases.

    Polling would be nice, but I want to reduce the complexity of this, and laptop users should know how long their battery lasts.

  18. changed the title [-]Don't start the backup on metered connections[/-] [+]Only run backups when battery is full[/+] on Feb 15, 2021
  19. locked and limited conversation to collaborators on Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedThis issue is available, comment if you want to fix itstatus:planningFor large features, plan it out before implementationtype:featureNew functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions