mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Allow to set custom backup archive name
This commit is contained in:
parent
2090958c8a
commit
fdb51ac200
4 changed files with 21 additions and 5 deletions
|
@ -564,6 +564,13 @@ backup:
|
|||
configuration:
|
||||
lock: false
|
||||
arguments:
|
||||
-n:
|
||||
full: --name
|
||||
help: Name of the backup archive
|
||||
extra:
|
||||
pattern:
|
||||
- '^[\w\-\.]{1,30}(?<!\.)$'
|
||||
- pattern_backup_archive_name
|
||||
--ignore-apps:
|
||||
help: Do not backup apps
|
||||
action: store_true
|
||||
|
|
14
backup.py
14
backup.py
|
@ -40,11 +40,12 @@ archives_path = '%s/archives' % backup_path
|
|||
logger = getActionLogger('yunohost.backup')
|
||||
|
||||
|
||||
def backup_create(ignore_apps=False):
|
||||
def backup_create(name=None, ignore_apps=False):
|
||||
"""
|
||||
Create a backup local archive
|
||||
|
||||
Keyword arguments:
|
||||
name -- Name of the backup archive
|
||||
ignore_apps -- Do not backup apps
|
||||
|
||||
"""
|
||||
|
@ -52,7 +53,11 @@ def backup_create(ignore_apps=False):
|
|||
from yunohost.hook import hook_callback
|
||||
|
||||
timestamp = int(time.time())
|
||||
tmp_dir = "%s/tmp/%s" % (backup_path, timestamp)
|
||||
if not name:
|
||||
name = str(timestamp)
|
||||
if name in backup_list()['archives']:
|
||||
raise MoulinetteError(errno.EINVAL, m18n.n('backup_archive_name_exists'))
|
||||
tmp_dir = "%s/tmp/%s" % (backup_path, name)
|
||||
|
||||
# Initialize backup info
|
||||
info = {
|
||||
|
@ -104,7 +109,7 @@ def backup_create(ignore_apps=False):
|
|||
|
||||
# Create the archive
|
||||
msignals.display(m18n.n('backup_creating_archive'))
|
||||
archive_file = "%s/%s.tar.gz" % (archives_path, timestamp)
|
||||
archive_file = "%s/%s.tar.gz" % (archives_path, name)
|
||||
try:
|
||||
tar = tarfile.open(archive_file, "w:gz")
|
||||
except:
|
||||
|
@ -129,8 +134,7 @@ def backup_create(ignore_apps=False):
|
|||
tar.close()
|
||||
|
||||
# Copy info file and remove temporary directory
|
||||
os.system('mv %s/info.json %s/%s.info.json' %
|
||||
(tmp_dir, archives_path, timestamp))
|
||||
os.system('mv %s/info.json %s/%s.info.json' % (tmp_dir, archives_path, name))
|
||||
os.system('rm -rf %s' % tmp_dir)
|
||||
|
||||
msignals.display(m18n.n('backup_complete'), 'success')
|
||||
|
|
|
@ -133,6 +133,7 @@
|
|||
"backup_extracting_archive" : "Extracting the backup archive...",
|
||||
"backup_archive_open_failed" : "Unable to open the backup archive",
|
||||
"backup_archive_name_unknown" : "Unknown local backup archive name",
|
||||
"backup_archive_name_exists" : "Backup archive name already exists",
|
||||
"backup_complete" : "Backup complete",
|
||||
"backup_invalid_archive" : "Invalid backup archive",
|
||||
"restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]",
|
||||
|
@ -173,6 +174,7 @@
|
|||
"pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)",
|
||||
"pattern_listname" : "Must be alphanumeric and underscore characters only",
|
||||
"pattern_port" : "Must be a valid port number (i.e. 0-65535)",
|
||||
"pattern_backup_archive_name" : "Must be a valid filename with alphanumeric and -_. characters only",
|
||||
|
||||
"format_datetime_short" : "%m/%d/%Y %I:%M %p"
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@
|
|||
"backup_extracting_archive" : "Extraction de l'archive de sauvegarde...",
|
||||
"backup_archive_open_failed" : "Impossible d'ouvrir l'archive de sauvegarde",
|
||||
"backup_archive_name_unknown" : "Nom d'archive de sauvegarde locale inconnu",
|
||||
"backup_archive_name_exists" : "Une archive de sauvegarde avec ce nom existe déjà",
|
||||
"backup_complete" : "Sauvegarde terminée",
|
||||
"backup_invalid_archive" : "Archive de sauvegarde incorrecte",
|
||||
"restore_confirm_yunohost_installed" : "Voulez-vous vraiment restaurer un système déjà installé ? [{answers:s}]",
|
||||
|
@ -173,6 +174,8 @@
|
|||
"pattern_domain" : "Doit être un nom de domaine valide (ex : mon-domaine.org)",
|
||||
"pattern_listname" : "Doit être composé uniquement de caractères alphanumérique et de tiret bas",
|
||||
"pattern_port" : "Doit être un numéro de port valide (0-65535)",
|
||||
"pattern_backup_archive_name" : "Doit être un nom de fichier valide composé de caractères alphanumérique et -_. uniquement",
|
||||
|
||||
"format_datetime_short" : "%d/%m/%Y %H:%M"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue