[backup] improvement: remove_method option

This commit is contained in:
Vinicius Moreira
2022-03-29 19:01:31 -03:00
parent da8a4e6547
commit a904c73b2d
15 changed files with 111 additions and 25 deletions

View File

@@ -18,7 +18,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- General - General
- code refactoring - code refactoring
- backup: - backup:
- single mode: only removing self generated snapshots (now the snapshots are associated with the comment "<bauh>") [#244](https://github.com/vinifmor/bauh/issues/244) - single mode: now supports two remove methods [#244](https://github.com/vinifmor/bauh/issues/244)
- self: it removes only self generated backups/snapshots (default)
- all: it removes all existing backup/snapshots on the disc
<p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.10.1/bkp_remove.png">
</p>
- Arch - Arch
- text length of some popups reduced - text length of some popups reduced

View File

@@ -444,6 +444,7 @@ backup:
upgrade: null # defines if the backup should be performed before upgrading a package. Allowed values: null (a dialog will be displayed asking if a snapshot should be generated), true: generates the backup without asking. false: disables the backup for this operation upgrade: null # defines if the backup should be performed before upgrading a package. Allowed values: null (a dialog will be displayed asking if a snapshot should be generated), true: generates the backup without asking. false: disables the backup for this operation
downgrade: null # defines if the backup should be performed before downgrading a package. Allowed values: null (a dialog will be displayed asking if a snapshot should be generated), true: generates the backup without asking. false: disables the backup for this operation downgrade: null # defines if the backup should be performed before downgrading a package. Allowed values: null (a dialog will be displayed asking if a snapshot should be generated), true: generates the backup without asking. false: disables the backup for this operation
type: rsync # defines the Timeshift backup mode -> 'rsync' (default) or 'btrfs' type: rsync # defines the Timeshift backup mode -> 'rsync' (default) or 'btrfs'
remove_method: self # define which backups should be removed in the 'only_one' mode. 'self': only self generated copies. 'all': all existing backups on the disc.
boot: boot:
load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true. load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true.
``` ```

View File

@@ -1,13 +1,12 @@
from typing import List, Tuple, Optional from typing import Tuple, Optional, Iterable
from bauh.api.abstract.view import SelectViewType, InputOption, SingleSelectComponent from bauh.api.abstract.view import SelectViewType, InputOption, SingleSelectComponent
SIZE_UNITS = ((1, 'B'), (1024, 'Kb'), (1048576, 'Mb'), (1073741824, 'Gb'), SIZE_UNITS = ((1, 'B'), (1024, 'Kb'), (1048576, 'Mb'), (1073741824, 'Gb'),
(1099511627776, 'Tb'), (1125899906842624, 'Pb')) (1099511627776, 'Tb'), (1125899906842624, 'Pb'))
def new_select(label: str, tip: str, id_: str, opts: List[Tuple[Optional[str], object, Optional[str]]], value: object, max_width: int, def new_select(label: str, tip: Optional[str], id_: str, opts: Iterable[Tuple[Optional[str], object, Optional[str]]], value: object, max_width: int,
type_: SelectViewType = SelectViewType.RADIO, capitalize_label: bool = True): type_: SelectViewType = SelectViewType.RADIO, capitalize_label: bool = True):
inp_opts = [InputOption(label=o[0].capitalize(), value=o[1], tooltip=o[2]) for o in opts] inp_opts = [InputOption(label=o[0].capitalize(), value=o[1], tooltip=o[2]) for o in opts]
def_opt = [o for o in inp_opts if o.value == value] def_opt = [o for o in inp_opts if o.value == value]

View File

@@ -3,6 +3,9 @@ from bauh.commons.config import YAMLConfigManager
FILE_PATH = f'{CONFIG_DIR}/config.yml' FILE_PATH = f'{CONFIG_DIR}/config.yml'
BACKUP_DEFAULT_REMOVE_METHOD = 'self'
BACKUP_REMOVE_METHODS = {BACKUP_DEFAULT_REMOVE_METHOD, 'all'}
class CoreConfigManager(YAMLConfigManager): class CoreConfigManager(YAMLConfigManager):
@@ -63,7 +66,8 @@ class CoreConfigManager(YAMLConfigManager):
'downgrade': None, 'downgrade': None,
'upgrade': None, 'upgrade': None,
'mode': 'incremental', 'mode': 'incremental',
'type': 'rsync' 'type': 'rsync',
'remove_method': 'self'
}, },
'boot': { 'boot': {
'load_apps': True 'load_apps': True

View File

@@ -16,7 +16,7 @@ from bauh.api.abstract.view import ViewComponent, TabComponent, InputOption, Tex
FileChooserComponent, RangeInputComponent FileChooserComponent, RangeInputComponent
from bauh.commons.view_utils import new_select from bauh.commons.view_utils import new_select
from bauh.view.core import timeshift from bauh.view.core import timeshift
from bauh.view.core.config import CoreConfigManager from bauh.view.core.config import CoreConfigManager, BACKUP_REMOVE_METHODS, BACKUP_DEFAULT_REMOVE_METHOD
from bauh.view.core.downloader import AdaptableFileDownloader from bauh.view.core.downloader import AdaptableFileDownloader
from bauh.view.util import translation from bauh.view.util import translation
from bauh.view.util.translation import I18n from bauh.view.util.translation import I18n
@@ -327,7 +327,7 @@ class GenericSettingsManager:
sub_comps = [FormComponent([select_locale, select_store_pwd, select_sysnotify, select_load_apps, select_sugs, inp_sugs, inp_reboot], spaces=False)] sub_comps = [FormComponent([select_locale, select_store_pwd, select_sysnotify, select_load_apps, select_sugs, inp_sugs, inp_reboot], spaces=False)]
return TabComponent(self.i18n['core.config.tab.general'].capitalize(), PanelComponent(sub_comps), None, 'core.gen') return TabComponent(self.i18n['core.config.tab.general'].capitalize(), PanelComponent(sub_comps), None, 'core.gen')
def _gen_bool_component(self, label: str, tooltip: str, value: bool, id_: str, max_width: int = 200) -> SingleSelectComponent: def _gen_bool_component(self, label: str, tooltip: Optional[str], value: bool, id_: str, max_width: int = 200) -> SingleSelectComponent:
opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True), opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True),
InputOption(label=self.i18n['no'].capitalize(), value=False)] InputOption(label=self.i18n['no'].capitalize(), value=False)]
@@ -397,6 +397,7 @@ class GenericSettingsManager:
core_config['backup']['enabled'] = bkp_form.get_component('enabled').get_selected() core_config['backup']['enabled'] = bkp_form.get_component('enabled').get_selected()
core_config['backup']['mode'] = bkp_form.get_component('mode').get_selected() core_config['backup']['mode'] = bkp_form.get_component('mode').get_selected()
core_config['backup']['type'] = bkp_form.get_component('type').get_selected() core_config['backup']['type'] = bkp_form.get_component('type').get_selected()
core_config['backup']['remove_method'] = bkp_form.get_component('remove_method').get_selected()
core_config['backup']['install'] = bkp_form.get_component('install').get_selected() core_config['backup']['install'] = bkp_form.get_component('install').get_selected()
core_config['backup']['uninstall'] = bkp_form.get_component('uninstall').get_selected() core_config['backup']['uninstall'] = bkp_form.get_component('uninstall').get_selected()
core_config['backup']['upgrade'] = bkp_form.get_component('upgrade').get_selected() core_config['backup']['upgrade'] = bkp_form.get_component('upgrade').get_selected()
@@ -580,5 +581,25 @@ class GenericSettingsManager:
max_width=default_width, max_width=default_width,
id_='type') id_='type')
sub_comps = [FormComponent([enabled_opt, mode, type_, install_mode, uninstall_mode, upgrade_mode, downgrade_mode], spaces=False)] remove_method = core_config['backup']['remove_method']
if not remove_method or remove_method not in BACKUP_REMOVE_METHODS:
remove_method = BACKUP_DEFAULT_REMOVE_METHOD
remove_i18n = 'core.config.backup.remove_method'
remove_opts = ((self.i18n[f'{remove_i18n}.{m}'], m, self.i18n[f'{remove_i18n}.{m}.tip'])
for m in sorted(BACKUP_REMOVE_METHODS))
remove_label = f'{self.i18n[remove_i18n]} ({self.i18n["core.config.backup.mode"]} ' \
f'"{self.i18n["core.config.backup.mode.only_one"].capitalize()}")'
sel_remove = new_select(label=remove_label,
tip=None,
value=remove_method,
opts=remove_opts,
max_width=default_width,
capitalize_label=False,
id_='remove_method')
sub_comps = [FormComponent([enabled_opt, type_, mode, sel_remove, install_mode, uninstall_mode, upgrade_mode, downgrade_mode], spaces=False)]
return TabComponent(self.i18n['core.config.tab.backup'].capitalize(), PanelComponent(sub_comps), None, 'core.bkp') return TabComponent(self.i18n['core.config.tab.backup'].capitalize(), PanelComponent(sub_comps), None, 'core.bkp')

View File

@@ -26,7 +26,7 @@ from bauh.commons.internet import InternetChecker
from bauh.commons.system import ProcessHandler, SimpleProcess from bauh.commons.system import ProcessHandler, SimpleProcess
from bauh.commons.view_utils import get_human_size_str from bauh.commons.view_utils import get_human_size_str
from bauh.view.core import timeshift from bauh.view.core import timeshift
from bauh.view.core.config import CoreConfigManager from bauh.view.core.config import CoreConfigManager, BACKUP_REMOVE_METHODS, BACKUP_DEFAULT_REMOVE_METHOD
from bauh.view.qt import commons from bauh.view.qt import commons
from bauh.view.qt.commons import sort_packages from bauh.view.qt.commons import sort_packages
from bauh.view.qt.view_model import PackageView, PackageViewStatus from bauh.view.qt.view_model import PackageView, PackageViewStatus
@@ -140,18 +140,28 @@ class AsyncAction(QThread, ProcessWatcher):
handler = ProcessHandler(self) handler = ProcessHandler(self)
if app_config['backup']['mode'] == 'only_one': if app_config['backup']['mode'] == 'only_one':
remove_method = app_config['backup']['remove_method']
if remove_method not in BACKUP_REMOVE_METHODS:
remove_method = BACKUP_DEFAULT_REMOVE_METHOD
delete_failed = False
if remove_method == 'self':
previous_snapshots = tuple(timeshift.read_created_snapshots(root_password)) previous_snapshots = tuple(timeshift.read_created_snapshots(root_password))
if previous_snapshots: if previous_snapshots:
substatus = f"[{self.i18n['core.config.tab.backup'].lower()}] {self.i18n['action.backup.substatus.delete']}" substatus = f"[{self.i18n['core.config.tab.backup'].lower()}] {self.i18n['action.backup.substatus.delete']}"
self.change_substatus(substatus) self.change_substatus(substatus)
delete_failed = False
for snapshot in reversed(previous_snapshots): for snapshot in reversed(previous_snapshots):
deleted, _ = handler.handle_simple(timeshift.delete(snapshot, root_password)) deleted, _ = handler.handle_simple(timeshift.delete(snapshot, root_password))
if not deleted: if not deleted:
delete_failed = True delete_failed = True
else:
deleted, _ = handler.handle_simple(timeshift.delete_all_snapshots(root_password))
delete_failed = not deleted
if delete_failed and not self.request_confirmation(title=self.i18n['core.config.tab.backup'], if delete_failed and not self.request_confirmation(title=self.i18n['core.config.tab.backup'],
body=f"{self.i18n['action.backup.error.delete']}. " body=f"{self.i18n['action.backup.error.delete']}. "

View File

@@ -211,6 +211,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy. core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy.
core.config.backup.mode.only_one=Single core.config.backup.mode.only_one=Single
core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased. core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased.
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Before uninstalling core.config.backup.uninstall=Before uninstalling
core.config.backup.upgrade=Before upgrading core.config.backup.upgrade=Before upgrading
core.config.boot.load_apps=Load apps after startup core.config.boot.load_apps=Load apps after startup

View File

@@ -210,6 +210,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy. core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy.
core.config.backup.mode.only_one=Single core.config.backup.mode.only_one=Single
core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased. core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased.
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Before uninstalling core.config.backup.uninstall=Before uninstalling
core.config.backup.upgrade=Before upgrading core.config.backup.upgrade=Before upgrading
core.config.boot.load_apps=Load apps after startup core.config.boot.load_apps=Load apps after startup

View File

@@ -211,6 +211,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased. core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased.
core.config.backup.mode.only_one=Single core.config.backup.mode.only_one=Single
core.config.backup.mode=Mode core.config.backup.mode=Mode
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Before uninstalling core.config.backup.uninstall=Before uninstalling
core.config.backup.upgrade=Before upgrading core.config.backup.upgrade=Before upgrading
core.config.backup=Enabled core.config.backup=Enabled

View File

@@ -211,6 +211,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.incremental.tip=Se generará una nueva copia de seguridad del sistema que contenga solo los archivos modificados desde la última copia. core.config.backup.mode.incremental.tip=Se generará una nueva copia de seguridad del sistema que contenga solo los archivos modificados desde la última copia.
core.config.backup.mode.only_one=Única core.config.backup.mode.only_one=Única
core.config.backup.mode.only_one.tip=Solo se guardará una copia de seguridad del sistema. Las copias preexistentes serán borradas. core.config.backup.mode.only_one.tip=Solo se guardará una copia de seguridad del sistema. Las copias preexistentes serán borradas.
core.config.backup.remove_method=Eliminar
core.config.backup.remove_method.self=Solo generadas
core.config.backup.remove_method.self.tip=Elimina solo las copias generadas por la aplicación
core.config.backup.remove_method.all=Todas
core.config.backup.remove_method.all.tip=Elimina todas las copias de seguridad existentes en el disco
core.config.backup.uninstall=Antes de desinstalar core.config.backup.uninstall=Antes de desinstalar
core.config.backup.upgrade=Antes de actualizar core.config.backup.upgrade=Antes de actualizar
core.config.boot.load_apps=Cargar aplicaciones al inicio core.config.boot.load_apps=Cargar aplicaciones al inicio

View File

@@ -209,6 +209,11 @@ core.config.backup.mode.incremental=Incrémental
core.config.backup.mode.only_one.tip=Une seule sauvegarde sera conservée. Les précédantes seront écrasées core.config.backup.mode.only_one.tip=Une seule sauvegarde sera conservée. Les précédantes seront écrasées
core.config.backup.mode.only_one=Seul core.config.backup.mode.only_one=Seul
core.config.backup.mode=Mode core.config.backup.mode=Mode
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Avant de désinstaller core.config.backup.uninstall=Avant de désinstaller
core.config.backup.upgrade=Avant de mettre à jour core.config.backup.upgrade=Avant de mettre à jour
core.config.backup=Activé core.config.backup=Activé

View File

@@ -210,6 +210,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy. core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy.
core.config.backup.mode.only_one=Single core.config.backup.mode.only_one=Single
core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased. core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased.
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Before uninstalling core.config.backup.uninstall=Before uninstalling
core.config.backup.upgrade=Before upgrading core.config.backup.upgrade=Before upgrading
core.config.boot.load_apps=Load apps after startup core.config.boot.load_apps=Load apps after startup

View File

@@ -209,6 +209,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.only_one.tip=Somente uma cópia de segurança do sistema será mantida. Pré-existentes serão apagadas core.config.backup.mode.only_one.tip=Somente uma cópia de segurança do sistema será mantida. Pré-existentes serão apagadas
core.config.backup.mode.only_one=Única core.config.backup.mode.only_one=Única
core.config.backup.mode=Modo core.config.backup.mode=Modo
core.config.backup.remove_method=Remover
core.config.backup.remove_method.self=Somente geradas
core.config.backup.remove_method.self.tip=Remove somente as cópia geradas pela aplicação
core.config.backup.remove_method.all=Todas
core.config.backup.remove_method.all.tip=Remove todas as cópias existentes no disco
core.config.backup.uninstall=Antes de desinstalar core.config.backup.uninstall=Antes de desinstalar
core.config.backup.upgrade=Antes de atualizar core.config.backup.upgrade=Antes de atualizar
core.config.backup=Habilitada core.config.backup=Habilitada

View File

@@ -210,6 +210,11 @@ core.config.backup.mode.incremental=Incremental
core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy. core.config.backup.mode.incremental.tip=A new system backup will be generated containing only the changed files since the latest copy.
core.config.backup.mode.only_one=Single core.config.backup.mode.only_one=Single
core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased. core.config.backup.mode.only_one.tip=Only one system backup will be kept. Pre-existing backups will be erased.
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Before uninstalling core.config.backup.uninstall=Before uninstalling
core.config.backup.upgrade=Before upgrading core.config.backup.upgrade=Before upgrading
core.config.boot.load_apps=Load apps after startup core.config.boot.load_apps=Load apps after startup

View File

@@ -209,6 +209,11 @@ core.config.backup.mode.incremental=Artan
core.config.backup.mode.only_one.tip=Yalnızca bir sistem yedeklemesi tutulur. Önceden var olan yedeklemeler silinecek. core.config.backup.mode.only_one.tip=Yalnızca bir sistem yedeklemesi tutulur. Önceden var olan yedeklemeler silinecek.
core.config.backup.mode.only_one=Tekil core.config.backup.mode.only_one=Tekil
core.config.backup.mode=Mod core.config.backup.mode=Mod
core.config.backup.remove_method=Remove
core.config.backup.remove_method.self=Only generated
core.config.backup.remove_method.self.tip=It removes only the self generated backups
core.config.backup.remove_method.all=All
core.config.backup.remove_method.all.tip=It removes all existing backups on the disc
core.config.backup.uninstall=Önce kaldırılıyor core.config.backup.uninstall=Önce kaldırılıyor
core.config.backup.upgrade=Önce yükseltiliyor core.config.backup.upgrade=Önce yükseltiliyor
core.config.backup=Etkin core.config.backup=Etkin