mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-25 04:46:58 +08:00
Implement auto-upgrade random runner
This commit is contained in:
parent
c8f578c831
commit
24a99ce177
6 changed files with 50 additions and 10 deletions
|
|
@ -548,13 +548,24 @@ This is free software, and you are welcome to redistribute it under certain cond
|
|||
auto_upgrade = full_config["global_options"]["auto_upgrade"]
|
||||
except KeyError:
|
||||
auto_upgrade = True
|
||||
try:
|
||||
auto_upgrade_percent_chance = full_config["global_options"][
|
||||
"auto_upgrade_percent_chance"
|
||||
]
|
||||
except KeyError:
|
||||
auto_upgrade_percent_chance = 50
|
||||
|
||||
# TODO: Deprecated auto_upgrade_interval in favor of auto_upgrade_percent_chance
|
||||
try:
|
||||
auto_upgrade_interval = full_config["global_options"]["auto_upgrade_interval"]
|
||||
except KeyError:
|
||||
auto_upgrade_interval = 10
|
||||
auto_upgrade_interval = None
|
||||
|
||||
if (
|
||||
auto_upgrade and upgrade_runner.need_upgrade(auto_upgrade_interval)
|
||||
auto_upgrade
|
||||
and upgrade_runner.need_upgrade(
|
||||
auto_upgrade_percent_chance, auto_upgrade_interval
|
||||
)
|
||||
) or args.auto_upgrade:
|
||||
if args.auto_upgrade:
|
||||
logger.info("Running user initiated auto upgrade")
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ empty_config_dict = {
|
|||
},
|
||||
"global_options": {
|
||||
"auto_upgrade": False,
|
||||
"auto_upgrade_interval": 10,
|
||||
"auto_upgrade_percent_chance": 5, # On all runs. On 15m interval runs, this could be 5% (ie once a day), on daily runs, this should be 95% (ie once a day)
|
||||
"auto_upgrade_server_url": None,
|
||||
"auto_upgrade_server_username": None,
|
||||
"auto_upgrade_server_password": None,
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@ __intname__ = "npbackup.gui.core.upgrade_runner"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2022-2025 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "2024041801"
|
||||
__build__ = "2025030601"
|
||||
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
import tempfile
|
||||
from logging import getLogger
|
||||
from random import randint
|
||||
from npbackup.upgrade_client.upgrader import auto_upgrader, _check_new_version
|
||||
import npbackup.configuration
|
||||
from npbackup.path_helper import CURRENT_DIR
|
||||
|
|
@ -22,8 +23,10 @@ from npbackup.path_helper import CURRENT_DIR
|
|||
logger = getLogger()
|
||||
|
||||
|
||||
def need_upgrade(upgrade_interval: int) -> bool:
|
||||
def _need_upgrade_interval(upgrade_interval: int) -> bool:
|
||||
"""
|
||||
TODO: Counter is now deprecated
|
||||
|
||||
Basic counter which allows an upgrade only every X times this is called so failed operations won't end in an endless upgrade loop
|
||||
|
||||
We need to make to select a write counter file that is writable
|
||||
|
|
@ -32,6 +35,7 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
|||
|
||||
The for loop logic isn't straight simple, but allows file fallback
|
||||
"""
|
||||
|
||||
# file counter, local, home, or temp if not available
|
||||
counter_file = "npbackup.autoupgrade.log"
|
||||
|
||||
|
|
@ -92,6 +96,27 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _need_upgrade_percent(upgrade_percent: int) -> bool:
|
||||
"""
|
||||
Randomly decide if we need an upgrade according to upgrade_percent
|
||||
"""
|
||||
if not upgrade_percent:
|
||||
return False
|
||||
if randint(1, 100) <= upgrade_percent:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def need_upgrade(upgrade_percent: int, upgrade_interval: int) -> bool:
|
||||
"""
|
||||
Decide if we need an upgrade according to upgrade_interval and upgrade_percent
|
||||
# TODO: Deprecate _need_upgrade_interval
|
||||
"""
|
||||
if _need_upgrade_percent(upgrade_percent) or _need_upgrade_interval(upgrade_interval):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def check_new_version(full_config: dict) -> bool:
|
||||
upgrade_url = full_config.g("global_options.auto_upgrade_server_url")
|
||||
username = full_config.g("global_options.auto_upgrade_server_username")
|
||||
|
|
|
|||
|
|
@ -1771,9 +1771,7 @@ def config_gui(full_config: dict, config_file: str):
|
|||
],
|
||||
[
|
||||
sg.Text(
|
||||
_t(
|
||||
"config_gui.post_backup_housekeeping_percent_chance_explanation"
|
||||
),
|
||||
_t("config_gui.post_backup_housekeeping_percent_chance"),
|
||||
size=(100, 1),
|
||||
),
|
||||
],
|
||||
|
|
@ -2099,6 +2097,10 @@ Google Cloud storage: GOOGLE_PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS\n\
|
|||
key="global_options.auto_upgrade_server_password", size=(50, 1)
|
||||
),
|
||||
],
|
||||
[
|
||||
sg.Text(_t("config_gui.auto_upgrade_percent_chance"), size=(40, 1)),
|
||||
sg.Input(key="global_options.auto_upgrade_percent_chance", size=(50, 1)),
|
||||
],
|
||||
[
|
||||
sg.Text(_t("config_gui.auto_upgrade_interval"), size=(40, 1)),
|
||||
sg.Input(key="global_options.auto_upgrade_interval", size=(50, 1)),
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ en:
|
|||
auto_upgrade_server_url: Server URL
|
||||
auto_upgrade_server_username: Server username
|
||||
auto_upgrade_server_password: Server password
|
||||
auto_upgrade_interval: Auto upgrade interval
|
||||
auto_upgrade_percent_chance: Auto upgrade percent chance (%%)
|
||||
auto_upgrade_interval: Auto upgrade interval (deprecated)
|
||||
auto_upgrade_launch: Launch auto upgrade
|
||||
auto_upgrade_will_quit: Warning, launching an upgrade procedure will quit this program without notice. You will have to wait 5 minutes before launching it again for the upgrade to complete
|
||||
auto_upgrade_failed: Auto upgrade procedure failed, see logs for further details
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ fr:
|
|||
auto_upgrade_server_url: Serveur de mise à niveau
|
||||
auto_upgrade_server_username: Nom d'utilisateur serveur
|
||||
auto_upgrade_server_password: Mot de passe serveur
|
||||
auto_upgrade_interval: Intervalle de mise à niveau
|
||||
auto_upgrade_percent_chance: Chance de mise à niveau automatique (%%)
|
||||
auto_upgrade_interval: Intervalle de mise à niveau (deprécié)
|
||||
auto_upgrade_launch: Lancer une mise à niveau
|
||||
auto_upgrade_will_quit: Attnetion, la procédure de mise à niveau va quitter ce programme sans notification. Vous devrez attendre 5 minutes pour laisser la procédure se terminer avant de relancer le programme
|
||||
auto_upgrade_failed: Procédure de mise à niveau échouée, veuillez consulter les journaux pour plus de détails
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue