mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Remove archivemount stuff (#491)
This commit is contained in:
parent
07b4ec49aa
commit
898d665900
3 changed files with 39 additions and 148 deletions
2
debian/control
vendored
2
debian/control
vendored
|
@ -33,7 +33,7 @@ Recommends: yunohost-admin
|
||||||
, python-pip
|
, python-pip
|
||||||
, unattended-upgrades
|
, unattended-upgrades
|
||||||
, libdbd-ldap-perl, libnet-dns-perl
|
, libdbd-ldap-perl, libnet-dns-perl
|
||||||
Suggests: htop, vim, rsync, acpi-support-base, udisks2, archivemount
|
Suggests: htop, vim, rsync, acpi-support-base, udisks2
|
||||||
Conflicts: iptables-persistent
|
Conflicts: iptables-persistent
|
||||||
, moulinette-yunohost, yunohost-config
|
, moulinette-yunohost, yunohost-config
|
||||||
, yunohost-config-others, yunohost-config-postfix
|
, yunohost-config-others, yunohost-config-postfix
|
||||||
|
|
|
@ -1316,9 +1316,7 @@ class BackupMethod(object):
|
||||||
TarBackupMethod
|
TarBackupMethod
|
||||||
---------------
|
---------------
|
||||||
This method compresses all files to backup in a .tar.gz archive. When
|
This method compresses all files to backup in a .tar.gz archive. When
|
||||||
restoring, it tries to mount the archive using archivemount/fuse instead
|
restoring, it untars the required parts.
|
||||||
of untaring the archive. Some systems don't support fuse (for these,
|
|
||||||
it automatically falls back to untaring the required parts).
|
|
||||||
|
|
||||||
CustomBackupMethod
|
CustomBackupMethod
|
||||||
------------------
|
------------------
|
||||||
|
@ -1687,8 +1685,7 @@ class CopyBackupMethod(BackupMethod):
|
||||||
|
|
||||||
class TarBackupMethod(BackupMethod):
|
class TarBackupMethod(BackupMethod):
|
||||||
"""
|
"""
|
||||||
This class compress all files to backup in archive. To restore it try to
|
This class compress all files to backup in archive.
|
||||||
mount the archive with archivemount (fuse). Some system don't support fuse.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, repo=None):
|
def __init__(self, repo=None):
|
||||||
|
@ -1760,8 +1757,6 @@ class TarBackupMethod(BackupMethod):
|
||||||
|
|
||||||
Exceptions:
|
Exceptions:
|
||||||
backup_archive_open_failed -- Raised if the archive can't be open
|
backup_archive_open_failed -- Raised if the archive can't be open
|
||||||
backup_archive_mount_failed -- Raised if the system don't support
|
|
||||||
archivemount
|
|
||||||
"""
|
"""
|
||||||
super(TarBackupMethod, self).mount(restore_manager)
|
super(TarBackupMethod, self).mount(restore_manager)
|
||||||
|
|
||||||
|
@ -1776,60 +1771,50 @@ class TarBackupMethod(BackupMethod):
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
# Mount the tarball
|
# Mount the tarball
|
||||||
|
logger.debug(m18n.n("restore_extracting"))
|
||||||
|
tar = tarfile.open(self._archive_file, "r:gz")
|
||||||
|
tar.extract('info.json', path=self.work_dir)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = subprocess.call(['archivemount', '-o', 'readonly',
|
tar.extract('backup.csv', path=self.work_dir)
|
||||||
self._archive_file, self.work_dir])
|
except KeyError:
|
||||||
except:
|
# Old backup archive have no backup.csv file
|
||||||
ret = -1
|
pass
|
||||||
|
|
||||||
# If archivemount failed, extract the archive
|
# Extract system parts backup
|
||||||
if ret != 0:
|
conf_extracted = False
|
||||||
logger.warning(m18n.n('backup_archive_mount_failed'))
|
|
||||||
|
|
||||||
logger.debug(m18n.n("restore_extracting"))
|
system_targets = self.manager.targets.list("system", exclude=["Skipped"])
|
||||||
tar = tarfile.open(self._archive_file, "r:gz")
|
apps_targets = self.manager.targets.list("apps", exclude=["Skipped"])
|
||||||
tar.extract('info.json', path=self.work_dir)
|
|
||||||
|
|
||||||
try:
|
for system_part in system_targets:
|
||||||
tar.extract('backup.csv', path=self.work_dir)
|
# Caution: conf_ynh_currenthost helpers put its files in
|
||||||
except KeyError:
|
# conf/ynh
|
||||||
# Old backup archive have no backup.csv file
|
if system_part.startswith("conf_"):
|
||||||
pass
|
if conf_extracted:
|
||||||
|
continue
|
||||||
# Extract system parts backup
|
system_part = "conf/"
|
||||||
conf_extracted = False
|
conf_extracted = True
|
||||||
|
else:
|
||||||
system_targets = self.manager.targets.list("system", exclude=["Skipped"])
|
system_part = system_part.replace("_", "/") + "/"
|
||||||
apps_targets = self.manager.targets.list("apps", exclude=["Skipped"])
|
|
||||||
|
|
||||||
for system_part in system_targets:
|
|
||||||
# Caution: conf_ynh_currenthost helpers put its files in
|
|
||||||
# conf/ynh
|
|
||||||
if system_part.startswith("conf_"):
|
|
||||||
if conf_extracted:
|
|
||||||
continue
|
|
||||||
system_part = "conf/"
|
|
||||||
conf_extracted = True
|
|
||||||
else:
|
|
||||||
system_part = system_part.replace("_", "/") + "/"
|
|
||||||
subdir_and_files = [
|
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
|
||||||
if tarinfo.name.startswith(system_part)
|
|
||||||
]
|
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
|
||||||
subdir_and_files = [
|
subdir_and_files = [
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
if tarinfo.name.startswith("hooks/restore/")
|
if tarinfo.name.startswith(system_part)
|
||||||
]
|
]
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
|
subdir_and_files = [
|
||||||
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
|
if tarinfo.name.startswith("hooks/restore/")
|
||||||
|
]
|
||||||
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
|
|
||||||
# Extract apps backup
|
# Extract apps backup
|
||||||
for app in apps_targets:
|
for app in apps_targets:
|
||||||
subdir_and_files = [
|
subdir_and_files = [
|
||||||
tarinfo for tarinfo in tar.getmembers()
|
tarinfo for tarinfo in tar.getmembers()
|
||||||
if tarinfo.name.startswith("apps/" + app)
|
if tarinfo.name.startswith("apps/" + app)
|
||||||
]
|
]
|
||||||
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
tar.extractall(members=subdir_and_files, path=self.work_dir)
|
||||||
|
|
||||||
|
|
||||||
class BorgBackupMethod(BackupMethod):
|
class BorgBackupMethod(BackupMethod):
|
||||||
|
|
|
@ -101,9 +101,6 @@ def app_is_installed(app):
|
||||||
|
|
||||||
def backup_test_dependencies_are_met():
|
def backup_test_dependencies_are_met():
|
||||||
|
|
||||||
# We need archivemount installed for the backup features to work
|
|
||||||
assert os.system("which archivemount >/dev/null") == 0
|
|
||||||
|
|
||||||
# Dummy test apps (or backup archives)
|
# Dummy test apps (or backup archives)
|
||||||
assert os.path.exists("./tests/apps/backup_wordpress_from_2p4")
|
assert os.path.exists("./tests/apps/backup_wordpress_from_2p4")
|
||||||
assert os.path.exists("./tests/apps/backup_legacy_app_ynh")
|
assert os.path.exists("./tests/apps/backup_legacy_app_ynh")
|
||||||
|
@ -250,42 +247,6 @@ def test_backup_and_restore_all_sys():
|
||||||
assert os.path.exists("/etc/ssowat/conf.json")
|
assert os.path.exists("/etc/ssowat/conf.json")
|
||||||
|
|
||||||
|
|
||||||
def test_backup_and_restore_archivemount_failure(monkeypatch, mocker):
|
|
||||||
|
|
||||||
# Create the backup
|
|
||||||
backup_create(ignore_system=False, ignore_apps=True)
|
|
||||||
|
|
||||||
archives = backup_list()["archives"]
|
|
||||||
assert len(archives) == 1
|
|
||||||
|
|
||||||
archives_info = backup_info(archives[0], with_details=True)
|
|
||||||
assert archives_info["apps"] == {}
|
|
||||||
assert (len(archives_info["system"].keys()) ==
|
|
||||||
len(os.listdir("/usr/share/yunohost/hooks/backup/")))
|
|
||||||
|
|
||||||
# Remove ssowat conf
|
|
||||||
assert os.path.exists("/etc/ssowat/conf.json")
|
|
||||||
os.system("rm -rf /etc/ssowat/")
|
|
||||||
assert not os.path.exists("/etc/ssowat/conf.json")
|
|
||||||
|
|
||||||
def custom_subprocess_call(*args, **kwargs):
|
|
||||||
import subprocess as subprocess2
|
|
||||||
if args[0] and args[0][0]=="archivemount":
|
|
||||||
monkeypatch.undo()
|
|
||||||
return 1
|
|
||||||
return subprocess.call(*args, **kwargs)
|
|
||||||
|
|
||||||
monkeypatch.setattr("subprocess.call", custom_subprocess_call)
|
|
||||||
mocker.spy(m18n, "n")
|
|
||||||
|
|
||||||
# Restore the backup
|
|
||||||
backup_restore(auth, name=archives[0], force=True,
|
|
||||||
ignore_system=False, ignore_apps=True)
|
|
||||||
|
|
||||||
# Check ssowat conf is back
|
|
||||||
assert os.path.exists("/etc/ssowat/conf.json")
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# System restore from 2.4 #
|
# System restore from 2.4 #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -311,38 +272,6 @@ def test_restore_system_from_Ynh2p4(monkeypatch, mocker):
|
||||||
ignore_apps=True,
|
ignore_apps=True,
|
||||||
force=True)
|
force=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_system_archive_from_2p4
|
|
||||||
def test_restore_system_from_Ynh2p4_archivemount_failure(monkeypatch, mocker):
|
|
||||||
|
|
||||||
# Backup current system
|
|
||||||
backup_create(ignore_system=False, ignore_apps=True)
|
|
||||||
archives = backup_list()["archives"]
|
|
||||||
assert len(archives) == 2
|
|
||||||
|
|
||||||
def custom_subprocess_call(*args, **kwargs):
|
|
||||||
import subprocess as subprocess2
|
|
||||||
if args[0] and args[0][0]=="archivemount":
|
|
||||||
monkeypatch.undo()
|
|
||||||
return 1
|
|
||||||
return subprocess.call(*args, **kwargs)
|
|
||||||
|
|
||||||
monkeypatch.setattr("subprocess.call", custom_subprocess_call)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Restore system from 2.4
|
|
||||||
backup_restore(auth, name=backup_list()["archives"][1],
|
|
||||||
ignore_system=False,
|
|
||||||
ignore_apps=True,
|
|
||||||
force=True)
|
|
||||||
finally:
|
|
||||||
# Restore system as it was
|
|
||||||
backup_restore(auth, name=backup_list()["archives"][0],
|
|
||||||
ignore_system=False,
|
|
||||||
ignore_apps=True,
|
|
||||||
force=True)
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# App backup #
|
# App backup #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -545,29 +474,6 @@ def test_restore_app_not_in_backup(mocker):
|
||||||
assert not _is_installed("yoloswag")
|
assert not _is_installed("yoloswag")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_wordpress_archive_from_2p4
|
|
||||||
def test_restore_app_archivemount_failure(monkeypatch, mocker):
|
|
||||||
|
|
||||||
def custom_subprocess_call(*args, **kwargs):
|
|
||||||
import subprocess as subprocess2
|
|
||||||
if args[0] and args[0][0]=="archivemount":
|
|
||||||
monkeypatch.undo()
|
|
||||||
return 1
|
|
||||||
return subprocess.call(*args, **kwargs)
|
|
||||||
|
|
||||||
monkeypatch.setattr("subprocess.call", custom_subprocess_call)
|
|
||||||
mocker.spy(m18n, "n")
|
|
||||||
|
|
||||||
assert not _is_installed("wordpress")
|
|
||||||
|
|
||||||
backup_restore(auth, name=backup_list()["archives"][0],
|
|
||||||
ignore_system=True,
|
|
||||||
ignore_apps=False,
|
|
||||||
apps=["wordpress"])
|
|
||||||
|
|
||||||
assert _is_installed("wordpress")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_wordpress_archive_from_2p4
|
@pytest.mark.with_wordpress_archive_from_2p4
|
||||||
def test_restore_app_already_installed(mocker):
|
def test_restore_app_already_installed(mocker):
|
||||||
|
|
||||||
|
@ -643,7 +549,7 @@ def test_restore_archive_with_no_json(mocker):
|
||||||
# Create a backup with no info.json associated
|
# Create a backup with no info.json associated
|
||||||
os.system("touch /tmp/afile")
|
os.system("touch /tmp/afile")
|
||||||
os.system("tar -czvf /home/yunohost.backup/archives/badbackup.tar.gz /tmp/afile")
|
os.system("tar -czvf /home/yunohost.backup/archives/badbackup.tar.gz /tmp/afile")
|
||||||
|
|
||||||
assert "badbackup" in backup_list()["archives"]
|
assert "badbackup" in backup_list()["archives"]
|
||||||
|
|
||||||
mocker.spy(m18n, "n")
|
mocker.spy(m18n, "n")
|
||||||
|
|
Loading…
Add table
Reference in a new issue