mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Fix counter-intuitive backup API (#490)
* Remove old/deprecated --hooks * Remove --ignore-system and --ignore-apps, backup/restore everything by default, or only the parts explicitly given
This commit is contained in:
parent
8df696849b
commit
8268d6e074
2 changed files with 13 additions and 95 deletions
|
@ -780,7 +780,7 @@ backup:
|
||||||
|
|
||||||
### backup_create()
|
### backup_create()
|
||||||
create:
|
create:
|
||||||
action_help: Create a backup local archive
|
action_help: Create a backup local archive. If neither --apps or --system are given, this will backup all apps and all system parts. If only --apps if given, this will only backup apps and no system parts. Similarly, if only --system is given, this will only backup system parts and no apps.
|
||||||
api: POST /backup
|
api: POST /backup
|
||||||
arguments:
|
arguments:
|
||||||
-n:
|
-n:
|
||||||
|
@ -804,28 +804,15 @@ backup:
|
||||||
help: List of backup methods to apply (copy or tar by default)
|
help: List of backup methods to apply (copy or tar by default)
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
--system:
|
--system:
|
||||||
help: List of system parts to backup (all by default)
|
help: List of system parts to backup (or all if none given).
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
--apps:
|
--apps:
|
||||||
help: List of application names to backup (all by default)
|
help: List of application names to backup (or all if none given)
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
--hooks:
|
|
||||||
help: (Deprecated) See --system
|
|
||||||
nargs: "*"
|
|
||||||
--ignore-system:
|
|
||||||
help: Do not backup system
|
|
||||||
action: store_true
|
|
||||||
--ignore-apps:
|
|
||||||
help: Do not backup apps
|
|
||||||
action: store_true
|
|
||||||
--ignore-hooks:
|
|
||||||
help: (Deprecated) See --ignore-system
|
|
||||||
action: store_true
|
|
||||||
|
|
||||||
|
|
||||||
### backup_restore()
|
### backup_restore()
|
||||||
restore:
|
restore:
|
||||||
action_help: Restore from a local backup archive
|
action_help: Restore from a local backup archive. If neither --apps or --system are given, this will restore all apps and all system parts in the archive. If only --apps if given, this will only restore apps and no system parts. Similarly, if only --system is given, this will only restore system parts and no apps.
|
||||||
api: POST /backup/restore/<name>
|
api: POST /backup/restore/<name>
|
||||||
configuration:
|
configuration:
|
||||||
authenticate: all
|
authenticate: all
|
||||||
|
@ -834,23 +821,11 @@ backup:
|
||||||
name:
|
name:
|
||||||
help: Name of the local backup archive
|
help: Name of the local backup archive
|
||||||
--system:
|
--system:
|
||||||
help: List of system parts to restore (all by default)
|
help: List of system parts to restore (or all if none is given)
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
--apps:
|
--apps:
|
||||||
help: List of application names to restore (all by default)
|
help: List of application names to restore (or all if none is given)
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
--hooks:
|
|
||||||
help: (Deprecated) See --system
|
|
||||||
nargs: "*"
|
|
||||||
--ignore-system:
|
|
||||||
help: Do not restore system parts
|
|
||||||
action: store_true
|
|
||||||
--ignore-apps:
|
|
||||||
help: Do not restore apps
|
|
||||||
action: store_true
|
|
||||||
--ignore-hooks:
|
|
||||||
help: (Deprecated) See --ignore-system
|
|
||||||
action: store_true
|
|
||||||
--force:
|
--force:
|
||||||
help: Force restauration on an already installed system
|
help: Force restauration on an already installed system
|
||||||
action: store_true
|
action: store_true
|
||||||
|
|
|
@ -1959,9 +1959,7 @@ class CustomBackupMethod(BackupMethod):
|
||||||
|
|
||||||
def backup_create(name=None, description=None, methods=[],
|
def backup_create(name=None, description=None, methods=[],
|
||||||
output_directory=None, no_compress=False,
|
output_directory=None, no_compress=False,
|
||||||
ignore_system=False, system=[],
|
system=[], apps=[]):
|
||||||
ignore_apps=False, apps=[],
|
|
||||||
ignore_hooks=False, hooks=[]):
|
|
||||||
"""
|
"""
|
||||||
Create a backup local archive
|
Create a backup local archive
|
||||||
|
|
||||||
|
@ -1972,12 +1970,7 @@ def backup_create(name=None, description=None, methods=[],
|
||||||
output_directory -- Output directory for the backup
|
output_directory -- Output directory for the backup
|
||||||
no_compress -- Do not create an archive file
|
no_compress -- Do not create an archive file
|
||||||
system -- List of system elements to backup
|
system -- List of system elements to backup
|
||||||
ignore_system -- Ignore system elements
|
|
||||||
apps -- List of application names to backup
|
apps -- List of application names to backup
|
||||||
ignore_apps -- Do not backup apps
|
|
||||||
|
|
||||||
hooks -- (Deprecated) Renamed to "system"
|
|
||||||
ignore_hooks -- (Deprecated) Renamed to "ignore_system"
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: Add a 'clean' argument to clean output directory
|
# TODO: Add a 'clean' argument to clean output directory
|
||||||
|
@ -1986,22 +1979,6 @@ def backup_create(name=None, description=None, methods=[],
|
||||||
# Validate / parse arguments #
|
# Validate / parse arguments #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
# Historical, deprecated options
|
|
||||||
if ignore_hooks is not False:
|
|
||||||
logger.warning("--ignore-hooks is deprecated and will be removed in the"
|
|
||||||
"future. Please use --ignore-system instead.")
|
|
||||||
ignore_system = ignore_hooks
|
|
||||||
|
|
||||||
if hooks != [] and hooks is not None:
|
|
||||||
logger.warning("--hooks is deprecated and will be removed in the"
|
|
||||||
"future. Please use --system instead.")
|
|
||||||
system = hooks
|
|
||||||
|
|
||||||
# Validate that there's something to backup
|
|
||||||
if ignore_system and ignore_apps:
|
|
||||||
raise MoulinetteError(errno.EINVAL,
|
|
||||||
m18n.n('backup_action_required'))
|
|
||||||
|
|
||||||
# Validate there is no archive with the same name
|
# Validate there is no archive with the same name
|
||||||
if name and name in backup_list()['archives']:
|
if name and name in backup_list()['archives']:
|
||||||
raise MoulinetteError(errno.EINVAL,
|
raise MoulinetteError(errno.EINVAL,
|
||||||
|
@ -2034,14 +2011,9 @@ def backup_create(name=None, description=None, methods=[],
|
||||||
else:
|
else:
|
||||||
methods = ['tar'] # In future, borg will be the default actions
|
methods = ['tar'] # In future, borg will be the default actions
|
||||||
|
|
||||||
if ignore_system:
|
# If no --system or --apps given, backup everything
|
||||||
system = None
|
if system is None and apps is None:
|
||||||
elif system is None:
|
|
||||||
system = []
|
system = []
|
||||||
|
|
||||||
if ignore_apps:
|
|
||||||
apps = None
|
|
||||||
elif apps is None:
|
|
||||||
apps = []
|
apps = []
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
@ -2090,11 +2062,7 @@ def backup_create(name=None, description=None, methods=[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def backup_restore(auth, name,
|
def backup_restore(auth, name, system=[], apps=[], force=False):
|
||||||
system=[], ignore_system=False,
|
|
||||||
apps=[], ignore_apps=False,
|
|
||||||
hooks=[], ignore_hooks=False,
|
|
||||||
force=False):
|
|
||||||
"""
|
"""
|
||||||
Restore from a local backup archive
|
Restore from a local backup archive
|
||||||
|
|
||||||
|
@ -2102,48 +2070,23 @@ def backup_restore(auth, name,
|
||||||
name -- Name of the local backup archive
|
name -- Name of the local backup archive
|
||||||
force -- Force restauration on an already installed system
|
force -- Force restauration on an already installed system
|
||||||
system -- List of system parts to restore
|
system -- List of system parts to restore
|
||||||
ignore_system -- Do not restore any system parts
|
|
||||||
apps -- List of application names to restore
|
apps -- List of application names to restore
|
||||||
ignore_apps -- Do not restore apps
|
|
||||||
|
|
||||||
hooks -- (Deprecated) Renamed to "system"
|
|
||||||
ignore_hooks -- (Deprecated) Renamed to "ignore_system"
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Validate / parse arguments #
|
# Validate / parse arguments #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
# Historical, deprecated options
|
# If no --system or --apps given, restore everything
|
||||||
if ignore_hooks is not False:
|
if system is None and apps is None:
|
||||||
logger.warning("--ignore-hooks is deprecated and will be removed in the"
|
|
||||||
"future. Please use --ignore-system instead.")
|
|
||||||
ignore_system = ignore_hooks
|
|
||||||
if hooks != [] and hooks is not None:
|
|
||||||
logger.warning("--hooks is deprecated and will be removed in the"
|
|
||||||
"future. Please use --system instead.")
|
|
||||||
system = hooks
|
|
||||||
|
|
||||||
# Validate what to restore
|
|
||||||
if ignore_system and ignore_apps:
|
|
||||||
raise MoulinetteError(errno.EINVAL,
|
|
||||||
m18n.n('restore_action_required'))
|
|
||||||
|
|
||||||
if ignore_system:
|
|
||||||
system = None
|
|
||||||
elif system is None:
|
|
||||||
system = []
|
system = []
|
||||||
|
|
||||||
if ignore_apps:
|
|
||||||
apps = None
|
|
||||||
elif apps is None:
|
|
||||||
apps = []
|
apps = []
|
||||||
|
|
||||||
# TODO don't ask this question when restoring apps only and certain system
|
# TODO don't ask this question when restoring apps only and certain system
|
||||||
# parts
|
# parts
|
||||||
|
|
||||||
# Check if YunoHost is installed
|
# Check if YunoHost is installed
|
||||||
if os.path.isfile('/etc/yunohost/installed') and not ignore_system:
|
if system is not None and os.path.isfile('/etc/yunohost/installed'):
|
||||||
logger.warning(m18n.n('yunohost_already_installed'))
|
logger.warning(m18n.n('yunohost_already_installed'))
|
||||||
if not force:
|
if not force:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue