Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: Ask whether to backup the database ......................................................................
packaging: setup: Ask whether to backup the database Change-Id: I8e113bddaeeb71b00f5a524db0be3a24fa6f9907 Bug-Url: https://bugzilla.redhat.com/1059286 Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/setup/ovirt_engine_setup/dwhconstants.py M packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-dwh/db/schema.py 2 files changed, 77 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/82/26082/1 diff --git a/packaging/setup/ovirt_engine_setup/dwhconstants.py b/packaging/setup/ovirt_engine_setup/dwhconstants.py index ff17357..6954cb2 100644 --- a/packaging/setup/ovirt_engine_setup/dwhconstants.py +++ b/packaging/setup/ovirt_engine_setup/dwhconstants.py @@ -207,6 +207,14 @@ PGPASS_FILE = 'OVESETUP_DWH_DB/pgPassFile' NEW_DATABASE = 'OVESETUP_DWH_DB/newDatabase' + @osetupattrs( + answerfile=True, + summary=True, + description=_('Backup DWH database'), + ) + def PERFORM_BACKUP(self): + return 'OVESETUP_DWH_DB/performBackup' + @util.export @util.codegen diff --git a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-dwh/db/schema.py b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-dwh/db/schema.py index 6dce348..8cd7417 100644 --- a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-dwh/db/schema.py +++ b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-dwh/db/schema.py @@ -159,6 +159,73 @@ ) ) + def _getDBSize(self): + # Returns db size in MB + statement = database.Statement( + dbenvkeys=odwhcons.Const.DWH_DB_ENV_KEYS, + environment=self.environment, + ) + result = statement.execute( + statement="SELECT pg_database_size(%(db)s) as size" + args=dict( + db=self.environment[odwhcons.DBEnv.DATABASE], + ), + ownConnection=True, + transaction=False, + ) + return int(result[0]['size']) / pow(2,20) + + def _getSizeHuman(size_in_mb): + return ( + _('{size} MB').format(size=size_in_mb) + if size_in_mb < 1024 + else _('{size} GB').format(size=float(size_in_mb/pow(2, 10))) + ) + + @plugin.event( + stage=plugin.Stages.STAGE_INIT, + ) + def _init(self): + self.environment.setdefault( + odwhcons.DBEnv.PERFORM_BACKUP, + None, + ) + + @plugin.event( + stage=plugin.Stages.STAGE_CUSTOMIZATION, + condition=lambda self: not self.environment[ + odwhcons.DBEnv.NEW_DATABASE + ], + before=( + osetupcons.Stages.DIALOG_TITLES_E_DATABASE, + ), + after=( + odwhcons.Stages.DB_CONNECTION_CUSTOMIZATION, + ), + ) + def _customization(self): + if self.environment[odwhcons.DBEnv.PERFORM_BACKUP] is None: + self.environment[ + odwhcons.DBEnv.PERFORM_BACKUP + ] = dialog.queryBoolean( + dialog=self.dialog, + name='OVESETUP_DWH_PERFORM_BACKUP', + note=_( + 'Setup can backup the existing database. The time and ' + 'space required for the database backup depend on its ' + 'size. The detected DB size is {dbsize}. This process ' + 'takes time, and in some cases (for instance, when the ' + 'size is few GBs) may take few hours to complete. Would ' + 'you like to backup the existing database before ' + 'upgrading it?' + '(@VALUES@) [@DEFAULT@]: ' + ), + prompt=True, + true=_('Yes'), + false=_('No'), + default=True, + ) + @plugin.event( stage=plugin.Stages.STAGE_VALIDATION, after=( @@ -189,6 +256,8 @@ if not self.environment[ odwhcons.DBEnv.NEW_DATABASE + ] and self.environment[ + odwhcons.DBEnv.PERFORM_BACKUP ]: dbovirtutils = database.OvirtUtils( plugin=self, -- To view, visit http://gerrit.ovirt.org/26082 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8e113bddaeeb71b00f5a524db0be3a24fa6f9907 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-dwh Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches