Simplified db dumps restore
This commit is contained in:
@@ -77,16 +77,9 @@ 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:
|
if self.restore:
|
||||||
utils.printcolor(
|
db_dump_path = self._restore_database_dump("amavis")
|
||||||
"Trying to restore amavis database from backup.", utils.MAGENTA)
|
if db_dump_path is not None:
|
||||||
amavis_db_backup_path = os.path.join(
|
return db_dump_path
|
||||||
self.restore, "databases/amavis.sql")
|
|
||||||
if os.path.isfile(amavis_db_backup_path):
|
|
||||||
utils.printcolor(
|
|
||||||
"Amavis database backup found ! Restoring...", utils.GREEN)
|
|
||||||
return amavis_db_backup_path
|
|
||||||
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:
|
||||||
|
|||||||
@@ -160,6 +160,20 @@ class Installer(object):
|
|||||||
self.post_run()
|
self.post_run()
|
||||||
self.restart_daemon()
|
self.restart_daemon()
|
||||||
|
|
||||||
|
def _restore_database_dump(self, app_name):
|
||||||
|
"""Restore database dump from a dump."""
|
||||||
|
|
||||||
|
utils.printcolor(
|
||||||
|
f"Trying to restore {app_name} database from backup.", utils.MAGENTA)
|
||||||
|
database_backup_path = os.path.join(
|
||||||
|
self.restore, f"databases/{app_name}.sql")
|
||||||
|
if os.path.isfile(database_backup_path):
|
||||||
|
utils.printcolor(
|
||||||
|
f"{app_name.capitalize()} database backup found ! Restoring...", utils.GREEN)
|
||||||
|
return database_backup_path
|
||||||
|
utils.printcolor(
|
||||||
|
f"{app_name.capitalize()} database backup not found, creating empty database.", utils.RED)
|
||||||
|
|
||||||
def pre_run(self):
|
def pre_run(self):
|
||||||
"""Tasks to execute before the installer starts."""
|
"""Tasks to execute before the installer starts."""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -180,16 +180,9 @@ class Modoboa(base.Installer):
|
|||||||
|
|
||||||
def get_sql_schema_path(self):
|
def get_sql_schema_path(self):
|
||||||
if self.restore:
|
if self.restore:
|
||||||
utils.printcolor(
|
db_dump_path = self._restore_database_dump("modoboa")
|
||||||
"Trying to restore modoboa database from backup.", utils.MAGENTA)
|
if db_dump_path is not None:
|
||||||
modoboa_database_backup_path = os.path.join(
|
return db_dump_path
|
||||||
self.restore, "databases/modoboa.sql")
|
|
||||||
if os.path.isfile(modoboa_database_backup_path):
|
|
||||||
utils.printcolor(
|
|
||||||
"Modoboa database backup found ! Restoring...", utils.GREEN)
|
|
||||||
return modoboa_database_backup_path
|
|
||||||
utils.printcolor(
|
|
||||||
"Modoboa database backup not found, creating empty database.", utils.RED)
|
|
||||||
|
|
||||||
return super().get_sql_schema_path()()
|
return super().get_sql_schema_path()()
|
||||||
|
|
||||||
|
|||||||
@@ -26,17 +26,9 @@ 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:
|
if self.restore:
|
||||||
utils.printcolor(
|
db_dump_path = self._restore_database_dump("spamassassin")
|
||||||
"Trying to restore spamassassin database from backup.", utils.MAGENTA)
|
if db_dump_path is not None:
|
||||||
sa_database_backup_path = os.path.join(
|
return db_dump_path
|
||||||
self.restore, "databases/spamassassin.sql")
|
|
||||||
if os.path.isfile(sa_database_backup_path):
|
|
||||||
utils.printcolor(
|
|
||||||
"Spamassassin database backup found ! Restoring...", utils.GREEN)
|
|
||||||
return sa_database_backup_path
|
|
||||||
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