[fix] Backup timer add

This commit is contained in:
ljf 2022-10-17 02:39:26 +02:00
parent fb62a9684b
commit 97ce3f188b
No known key found for this signature in database
4 changed files with 66 additions and 74 deletions

View file

@ -1272,11 +1272,6 @@ backup:
list: list:
action_help: List backup timer action_help: List backup timer
api: GET /backup/timer api: GET /backup/timer
arguments:
-r:
full: --repositories
help: List archives in these repositories
nargs: "*"
### backup_timer_add() ### backup_timer_add()
add: add:
@ -1307,13 +1302,13 @@ backup:
--alert: --alert:
help: Email to alert help: Email to alert
--keep-hourly: --keep-hourly:
default: 2 default: 0
--keep-daily: --keep-daily:
default: 7 default: 7
--keep-weekly: --keep-weekly:
default: 8 default: 8
--keep-monthly: --keep-monthly:
default: 12 default: 8
### backup_timer_update() ### backup_timer_update()
update: update:

View file

@ -1,6 +1,6 @@
version = "1.0" version = "1.0"
i18n = "repository_config" i18n = "backup_timer_config"
[main] [main]
name.en = "" name.en = ""
[main.main] [main.main]
@ -11,79 +11,53 @@ name.en = ""
type = "string" type = "string"
default = "" default = ""
[main.main.is_remote] [main.main.repositories]
type = "boolean" type = "tags"
yes = true
no = false
visible = "creation" visible = "creation"
default = "no" default = "no"
[main.main.domain] [main.main.system]
type = "tags"
default = []
[main.main.apps]
type = "tags"
default = []
[main.main.schedule]
type = "string" type = "string"
visible = "creation && is_remote" default = "Daily"
pattern.regexp = '^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+((xn--)?[^\W_]{2,})$'
pattern.error = 'domain_error' # TODO "Please provide a valid domain"
default = ""
# FIXME: can't be a domain of this instances ?
[main.main.is_shf]
help = ""
type = "boolean"
yes = true
no = false
visible = "creation && is_remote"
default = false
[main.main.public_key]
type = "alert"
style = "info"
visible = "creation && is_remote && ! is_shf"
[main.main.alert] [main.main.alert]
help = '' help = ''
type = "tags" type = "tags"
visible = "is_remote && is_shf"
pattern.regexp = '^[\w\+.-]+@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+((xn--)?[^\W_]{2,})$' pattern.regexp = '^[\w\+.-]+@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+((xn--)?[^\W_]{2,})$'
pattern.error = "alert_error" pattern.error = "alert_error"
default = [] default = []
# "value": alert, # "value": alert,
[main.main.alert_delay] [main.main.keep_hourly]
help = '' help = ''
type = "number" type = "number"
visible = "is_remote && is_shf" min = 0
min = 1 default = 0
default = 7
[main.main.quota]
type = "string"
visible = "is_remote && is_shf"
pattern.regexp = '^\d+[MGT]$'
pattern.error = '' # TODO ""
default = ""
[main.main.port]
type = "number"
visible = "is_remote && !is_shf"
min = 1
max = 65535
default = 22
[main.main.user]
type = "string"
visible = "is_remote && !is_shf"
default = ""
[main.main.method]
type = "select"
# "value": method,
choices.borg = "BorgBackup (recommended)"
choices.tar = "Legacy tar archive mechanism"
default = "borg"
visible = "!is_remote"
[main.main.path] [main.main.keep_daily]
type = "path" help = ''
visible = "!is_remote or (is_remote and !is_shf)" type = "number"
default = "/home/yunohost.backup/archives" min = 0
default = 10
[main.main.keep_weekly]
help = ''
type = "number"
min = 0
default = 8
[main.main.keep_monthly]
help = ''
type = "number"
min = 0
default = 8

View file

@ -2003,7 +2003,7 @@ class BackupTimer(ConfigPanel):
if os.path.exists(self.service_path) and os.path.isfile(self.service_path): if os.path.exists(self.service_path) and os.path.isfile(self.service_path):
raise NotImplementedError() # TODO raise NotImplementedError() # TODO
def _apply(self, values): def _apply(self):
write_to_file(self.save_path, f"""[Unit] write_to_file(self.save_path, f"""[Unit]
Description=Run backup {self.entity} regularly Description=Run backup {self.entity} regularly
@ -2025,6 +2025,24 @@ ExecStart=/usr/bin/yunohost backup create -n '{self.entity}' -r '{self.repositor
User=root User=root
Group=root Group=root
""") """)
@classmethod
def list(cls, full=False):
"""
List backup timer
"""
timers = super().list()
if not full:
return timers
full_timers = {}
for timer in timers:
try:
full_timers.update(BackupTimer(timer).info())
except Exception as e:
logger.error(f"Unable to open timer {timer}: {e}")
return full_timers
def backup_timer_list(full=False): def backup_timer_list(full=False):
@ -2034,19 +2052,20 @@ def backup_timer_list(full=False):
return {"backup_timer": BackupTimer.list(full)} return {"backup_timer": BackupTimer.list(full)}
def backup_timer_info(shortname, space_used=False): def backup_timer_info(name):
return BackupTimer(shortname).info(space_used) return BackupTimer(name).get()
@is_unit_operation() @is_unit_operation()
def backup_timer_add( def backup_timer_add(
operation_logger, operation_logger,
shortname=None, name=None,
description=None, description=None,
repos=[], repositories=[],
system=[], system=[],
apps=[], apps=[],
schedule=None, schedule=None,
alert=[],
keep_hourly=None, keep_hourly=None,
keep_daily=None, keep_daily=None,
keep_weekly=None, keep_weekly=None,
@ -2057,7 +2076,7 @@ def backup_timer_add(
Add a backup timer Add a backup timer
""" """
args = {k: v for k, v in locals().items() if v is not None} args = {k: v for k, v in locals().items() if v is not None}
timer = BackupTimer(shortname, creation=True) timer = BackupTimer(name, creation=True)
return timer.set( return timer.set(
operation_logger=args.pop('operation_logger'), operation_logger=args.pop('operation_logger'),
args=urllib.parse.urlencode(args) args=urllib.parse.urlencode(args)

View file

@ -39,6 +39,10 @@ class TarBackupRepository(LocalBackupRepository):
need_organized_files = False need_organized_files = False
method_name = "tar" method_name = "tar"
# =================================================
# Repository actions
# =================================================
def list_archives_names(self): def list_archives_names(self):
# Get local archives sorted according to last modification time # Get local archives sorted according to last modification time
# (we do a realpath() to resolve symlinks) # (we do a realpath() to resolve symlinks)