Add a --dry-run option to backup_create that returns the size of items that will be backed up

This commit is contained in:
Alexandre Aubin 2021-04-05 20:45:28 +02:00
parent 81c43747a0
commit 28268c58eb
3 changed files with 12 additions and 1 deletions

View file

@ -890,6 +890,9 @@ backup:
--apps:
help: List of application names to backup (or all if none given)
nargs: "*"
--dry-run:
help: "'Simulate' the backup and return the size details per item to backup"
action: store_true
### backup_restore()
restore:

View file

@ -93,6 +93,7 @@
"backup_copying_to_organize_the_archive": "Copying {size:s}MB to organize the archive",
"backup_couldnt_bind": "Could not bind {src:s} to {dest:s}.",
"backup_created": "Backup created",
"backup_create_size_estimation": "The archive will contain about {size} of data.",
"backup_creation_failed": "Could not create the backup archive",
"backup_csv_addition_failed": "Could not add files to backup into the CSV file",
"backup_csv_creation_failed": "Could not create the CSV file needed for restoration",

View file

@ -2138,7 +2138,7 @@ class CustomBackupMethod(BackupMethod):
@is_unit_operation()
def backup_create(
operation_logger,
name=None, description=None, methods=[], output_directory=None, system=[], apps=[]
name=None, description=None, methods=[], output_directory=None, system=[], apps=[], dry_run=False
):
"""
Create a backup local archive
@ -2220,8 +2220,15 @@ def backup_create(
# Collect files to be backup (by calling app backup script / system hooks)
backup_manager.collect_files()
if dry_run:
return {
"size": backup_manager.size,
"size_details": backup_manager.size_details
}
# Apply backup methods on prepared files
logger.info(m18n.n("backup_actually_backuping"))
logger.info(m18n.n("backup_create_size_estimation", size=binary_to_human(backup_manager.size) + "B"))
backup_manager.backup()
logger.success(m18n.n("backup_created"))