diff --git a/locales/en.json b/locales/en.json index 9290b7c24..78d1f0337 100644 --- a/locales/en.json +++ b/locales/en.json @@ -185,6 +185,7 @@ "backup_nothings_done" : "There is nothing to save", "backup_cleaning_failed" : "Unable to clean backup temporary directory", "backup_complete" : "Backup complete", + "backup_failed" : "Backup failed", "backup_invalid_archive" : "Invalid backup archive", "restore_action_required" : "You must specify something to restore", "restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]", diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 17d0064dd..59a266d9e 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -265,29 +265,29 @@ def backup_create(name=None, description=None, output_directory=None, if not no_compress: logger.info(m18n.n('backup_creating_archive')) archive_file = "%s/%s.tar.gz" % (output_directory, name) + # Create the archives directory + if not os.path.isdir(archives_path): + os.mkdir(archives_path, 0750) + + # Open archive file for writing try: tar = tarfile.open(archive_file, "w:gz") except: - tar = None + logger.debug("unable to open '%s' for writing", + archive_file, exc_info=1) - # Create the archives directory and retry - if not os.path.isdir(archives_path): - os.mkdir(archives_path, 0750) - try: - tar = tarfile.open(archive_file, "w:gz") - except: - logger.debug("unable to open '%s' for writing", - archive_file, exc_info=1) - tar = None - else: - logger.debug("unable to open '%s' for writing", - archive_file, exc_info=1) - if tar is None: - _clean_tmp_dir(2) - raise MoulinetteError(errno.EIO, - m18n.n('backup_archive_open_failed')) - tar.add(tmp_dir, arcname='') - tar.close() + _clean_tmp_dir(2) + raise MoulinetteError(errno.EIO, + m18n.n('backup_archive_open_failed')) + + # Write into archive + try: + tar.add(tmp_dir, arcname='') + tar.close() + except IOError as e: + logger.error(m18n.n('backup_archive_writing_error'), exc_info=1) + _clean_tmp_dir(3) + raise MoulinetteError(errno.EIO, m18n.n('backup_failed')) # Move info file os.rename(tmp_dir + '/info.json',