Restore workflow done
This commit is contained in:
@@ -40,3 +40,16 @@ def backup(config, bashArg, nomail):
|
|||||||
except utils.FatalError as inst:
|
except utils.FatalError as inst:
|
||||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def restore(restore):
|
||||||
|
"""Restore instance"""
|
||||||
|
try:
|
||||||
|
script = importlib.import_module(
|
||||||
|
"modoboa_installer.scripts.restore")
|
||||||
|
except ImportError:
|
||||||
|
print("Error importing restore")
|
||||||
|
try:
|
||||||
|
getattr(script, "Restore")(restore)
|
||||||
|
except utils.FatalError as inst:
|
||||||
|
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
"""Amavis related functions."""
|
"""Amavis related functions."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
|
|
||||||
from .. import package
|
from .. import package
|
||||||
from .. import utils
|
from .. import utils
|
||||||
@@ -43,6 +42,10 @@ class Amavis(base.Installer):
|
|||||||
def get_config_files(self):
|
def get_config_files(self):
|
||||||
"""Return appropriate config files."""
|
"""Return appropriate config files."""
|
||||||
if package.backend.FORMAT == "deb":
|
if package.backend.FORMAT == "deb":
|
||||||
|
amavisCustomConf = self.restore + "custom/99-custom"
|
||||||
|
if self.restore and os.path.isfile(amavisCustomConf):
|
||||||
|
utils.printcolor("Restoring custom Amavis configuration", utils.MAGENTA)
|
||||||
|
utils.copy_file(amavisCustomConf, self.config_dir)
|
||||||
return [
|
return [
|
||||||
"conf.d/05-node_id", "conf.d/15-content_filter_mode",
|
"conf.d/05-node_id", "conf.d/15-content_filter_mode",
|
||||||
"conf.d/50-user"]
|
"conf.d/50-user"]
|
||||||
@@ -70,6 +73,14 @@ class Amavis(base.Installer):
|
|||||||
|
|
||||||
def get_sql_schema_path(self):
|
def get_sql_schema_path(self):
|
||||||
"""Return schema path."""
|
"""Return schema path."""
|
||||||
|
if self.restore:
|
||||||
|
utils.printcolor("Trying to restore amavis database from backup", utils.MAGENTA)
|
||||||
|
amavisDbBackupPath = self.restore + "databases/amavis.sql"
|
||||||
|
if os.path.isfile(amavisDbBackupPath):
|
||||||
|
utils.printcolor("Amavis database backup found ! Restoring...", utils.GREEN)
|
||||||
|
return amavisDbBackupPath
|
||||||
|
utils.printcolor("Amavis database backup not found, creating empty database", utils.RED)
|
||||||
|
|
||||||
version = package.backend.get_installed_version("amavisd-new")
|
version = package.backend.get_installed_version("amavisd-new")
|
||||||
if version is None:
|
if version is None:
|
||||||
# Fallback to amavis...
|
# Fallback to amavis...
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
|
import shutil
|
||||||
|
|
||||||
from .. import database
|
from .. import database
|
||||||
from .. import package
|
from .. import package
|
||||||
@@ -87,6 +88,12 @@ class Dovecot(base.Installer):
|
|||||||
|
|
||||||
def post_run(self):
|
def post_run(self):
|
||||||
"""Additional tasks."""
|
"""Additional tasks."""
|
||||||
|
if self.restore and len(os.listdir(self.restore + "mails")) > 0:
|
||||||
|
utils.printcolor("Copying mail backup over dovecot directory", utils.MAGENTA)
|
||||||
|
shutil.copytree(self.restore+"mails/vmails", self.home_dir, dirs_exist_ok=True)
|
||||||
|
elif self.restore:
|
||||||
|
utils.printcolor("It seems that mails were not backed up, skipping mail restoration.", utils.MAGENTA)
|
||||||
|
|
||||||
if self.dbengine == "postgres":
|
if self.dbengine == "postgres":
|
||||||
dbname = self.config.get("modoboa", "dbname")
|
dbname = self.config.get("modoboa", "dbname")
|
||||||
dbuser = self.config.get("modoboa", "dbuser")
|
dbuser = self.config.get("modoboa", "dbuser")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Modoboa related tasks."""
|
"""Modoboa related tasks."""
|
||||||
|
|
||||||
|
from genericpath import isfile
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
@@ -176,6 +177,18 @@ class Modoboa(base.Installer):
|
|||||||
self.backend.grant_access(
|
self.backend.grant_access(
|
||||||
self.config.get("amavis", "dbname"), self.dbuser)
|
self.config.get("amavis", "dbname"), self.dbuser)
|
||||||
|
|
||||||
|
|
||||||
|
def get_sql_schema_path(self):
|
||||||
|
if self.restore:
|
||||||
|
utils.printcolor("Trying to restore modoboa database from backup", utils.MAGENTA)
|
||||||
|
modoboaDbBackupPath = self.restore + "databases/modoboa.sql"
|
||||||
|
if os.path.isfile(modoboaDbBackupPath):
|
||||||
|
utils.printcolor("Modoboa database backup found ! Restoring...", utils.GREEN)
|
||||||
|
return modoboaDbBackupPath
|
||||||
|
utils.printcolor("Modoboa database backup not found, creating empty database", utils.RED)
|
||||||
|
|
||||||
|
return super().get_sql_schema_path()()
|
||||||
|
|
||||||
def get_packages(self):
|
def get_packages(self):
|
||||||
"""Include extra packages if needed."""
|
"""Include extra packages if needed."""
|
||||||
packages = super(Modoboa, self).get_packages()
|
packages = super(Modoboa, self).get_packages()
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ class Postwhite(base.Installer):
|
|||||||
self.install_from_archive(SPF_TOOLS_REPOSITORY, install_dir)
|
self.install_from_archive(SPF_TOOLS_REPOSITORY, install_dir)
|
||||||
postw_dir = self.install_from_archive(
|
postw_dir = self.install_from_archive(
|
||||||
POSTWHITE_REPOSITORY, install_dir)
|
POSTWHITE_REPOSITORY, install_dir)
|
||||||
|
postwhiteBackupConf = self.restore+"custom/postwhite.conf"
|
||||||
|
if self.restore and os.path.isfile(postwhiteBackupConf):
|
||||||
|
utils.printcolor("Restoring postwhite.conf backup.", utils.MAGENTA)
|
||||||
|
utils.copy_file(postwhiteBackupConf, "/etc")
|
||||||
|
else:
|
||||||
utils.copy_file(os.path.join(postw_dir, "postwhite.conf"), "/etc")
|
utils.copy_file(os.path.join(postw_dir, "postwhite.conf"), "/etc")
|
||||||
postw_bin = os.path.join(postw_dir, "postwhite")
|
postw_bin = os.path.join(postw_dir, "postwhite")
|
||||||
utils.exec_cmd("{} /etc/postwhite.conf".format(postw_bin))
|
utils.exec_cmd("{} /etc/postwhite.conf".format(postw_bin))
|
||||||
|
|||||||
29
modoboa_installer/scripts/restore.py
Normal file
29
modoboa_installer/scripts/restore.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from ctypes import util
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
|
class Restore:
|
||||||
|
def __init__(self, restore):
|
||||||
|
"""Restoring pre-check (backup integriety)"""
|
||||||
|
"""REQUIRED : modoboa.sql"""
|
||||||
|
"""OPTIONAL : mails/, custom/, amavis.sql, spamassassin.sql"""
|
||||||
|
"""Only checking required"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not os.path.isdir(restore):
|
||||||
|
utils.printcolor("Provided path is not a directory !", utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
|
except:
|
||||||
|
utils.printcolor("Provided path is not right...", utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not os.path.isfile(restore+"databases/modoboa.sql"):
|
||||||
|
utils.printcolor(restore+"databases/modoboa.sql not found, please check your backup", utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
|
except:
|
||||||
|
utils.printcolor(restore+"databases/modoboa.sql not found, please check your backup", utils.RED)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
#Everything seems allright here, proceding...
|
||||||
@@ -25,6 +25,14 @@ class Spamassassin(base.Installer):
|
|||||||
|
|
||||||
def get_sql_schema_path(self):
|
def get_sql_schema_path(self):
|
||||||
"""Return SQL schema."""
|
"""Return SQL schema."""
|
||||||
|
if self.restore:
|
||||||
|
utils.printcolor("Trying to restore spamassassin database from backup", utils.MAGENTA)
|
||||||
|
amavisDbBackupPath = self.restore + "databases/spamassassin.sql"
|
||||||
|
if os.path.isfile(amavisDbBackupPath):
|
||||||
|
utils.printcolor("Spamassassin database backup found ! Restoring...", utils.GREEN)
|
||||||
|
return amavisDbBackupPath
|
||||||
|
utils.printcolor("Spamassassin database backup not found, creating empty database", utils.RED)
|
||||||
|
|
||||||
if self.dbengine == "postgres":
|
if self.dbengine == "postgres":
|
||||||
fname = "bayes_pg.sql"
|
fname = "bayes_pg.sql"
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user