mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Backup timer add
This commit is contained in:
parent
fb62a9684b
commit
97ce3f188b
4 changed files with 66 additions and 74 deletions
|
@ -1272,11 +1272,6 @@ backup:
|
|||
list:
|
||||
action_help: List backup timer
|
||||
api: GET /backup/timer
|
||||
arguments:
|
||||
-r:
|
||||
full: --repositories
|
||||
help: List archives in these repositories
|
||||
nargs: "*"
|
||||
|
||||
### backup_timer_add()
|
||||
add:
|
||||
|
@ -1307,13 +1302,13 @@ backup:
|
|||
--alert:
|
||||
help: Email to alert
|
||||
--keep-hourly:
|
||||
default: 2
|
||||
default: 0
|
||||
--keep-daily:
|
||||
default: 7
|
||||
--keep-weekly:
|
||||
default: 8
|
||||
--keep-monthly:
|
||||
default: 12
|
||||
default: 8
|
||||
|
||||
### backup_timer_update()
|
||||
update:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
version = "1.0"
|
||||
i18n = "repository_config"
|
||||
i18n = "backup_timer_config"
|
||||
[main]
|
||||
name.en = ""
|
||||
[main.main]
|
||||
|
@ -11,79 +11,53 @@ name.en = ""
|
|||
type = "string"
|
||||
default = ""
|
||||
|
||||
[main.main.is_remote]
|
||||
type = "boolean"
|
||||
yes = true
|
||||
no = false
|
||||
[main.main.repositories]
|
||||
type = "tags"
|
||||
visible = "creation"
|
||||
default = "no"
|
||||
|
||||
[main.main.domain]
|
||||
|
||||
[main.main.system]
|
||||
type = "tags"
|
||||
default = []
|
||||
|
||||
[main.main.apps]
|
||||
type = "tags"
|
||||
default = []
|
||||
|
||||
[main.main.schedule]
|
||||
type = "string"
|
||||
visible = "creation && is_remote"
|
||||
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"
|
||||
default = "Daily"
|
||||
|
||||
[main.main.alert]
|
||||
help = ''
|
||||
type = "tags"
|
||||
visible = "is_remote && is_shf"
|
||||
pattern.regexp = '^[\w\+.-]+@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+((xn--)?[^\W_]{2,})$'
|
||||
pattern.error = "alert_error"
|
||||
default = []
|
||||
# "value": alert,
|
||||
|
||||
[main.main.alert_delay]
|
||||
[main.main.keep_hourly]
|
||||
help = ''
|
||||
type = "number"
|
||||
visible = "is_remote && is_shf"
|
||||
min = 1
|
||||
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"
|
||||
min = 0
|
||||
default = 0
|
||||
|
||||
[main.main.path]
|
||||
type = "path"
|
||||
visible = "!is_remote or (is_remote and !is_shf)"
|
||||
default = "/home/yunohost.backup/archives"
|
||||
[main.main.keep_daily]
|
||||
help = ''
|
||||
type = "number"
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -2003,7 +2003,7 @@ class BackupTimer(ConfigPanel):
|
|||
if os.path.exists(self.service_path) and os.path.isfile(self.service_path):
|
||||
raise NotImplementedError() # TODO
|
||||
|
||||
def _apply(self, values):
|
||||
def _apply(self):
|
||||
write_to_file(self.save_path, f"""[Unit]
|
||||
Description=Run backup {self.entity} regularly
|
||||
|
||||
|
@ -2025,6 +2025,24 @@ ExecStart=/usr/bin/yunohost backup create -n '{self.entity}' -r '{self.repositor
|
|||
User=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):
|
||||
|
@ -2034,19 +2052,20 @@ def backup_timer_list(full=False):
|
|||
return {"backup_timer": BackupTimer.list(full)}
|
||||
|
||||
|
||||
def backup_timer_info(shortname, space_used=False):
|
||||
return BackupTimer(shortname).info(space_used)
|
||||
def backup_timer_info(name):
|
||||
return BackupTimer(name).get()
|
||||
|
||||
|
||||
@is_unit_operation()
|
||||
def backup_timer_add(
|
||||
operation_logger,
|
||||
shortname=None,
|
||||
name=None,
|
||||
description=None,
|
||||
repos=[],
|
||||
repositories=[],
|
||||
system=[],
|
||||
apps=[],
|
||||
schedule=None,
|
||||
alert=[],
|
||||
keep_hourly=None,
|
||||
keep_daily=None,
|
||||
keep_weekly=None,
|
||||
|
@ -2057,7 +2076,7 @@ def backup_timer_add(
|
|||
Add a backup timer
|
||||
"""
|
||||
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(
|
||||
operation_logger=args.pop('operation_logger'),
|
||||
args=urllib.parse.urlencode(args)
|
||||
|
|
|
@ -39,6 +39,10 @@ class TarBackupRepository(LocalBackupRepository):
|
|||
need_organized_files = False
|
||||
method_name = "tar"
|
||||
|
||||
# =================================================
|
||||
# Repository actions
|
||||
# =================================================
|
||||
|
||||
def list_archives_names(self):
|
||||
# Get local archives sorted according to last modification time
|
||||
# (we do a realpath() to resolve symlinks)
|
||||
|
|
Loading…
Add table
Reference in a new issue