From bb50a41c4af31e37aa8e7924e869a29de840eff2 Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Tue, 14 Apr 2026 13:34:20 +0100 Subject: [PATCH 1/2] remove truncate_database.bat in favour of ansible --- .../ibex_install_utils/install_tasks.py | 11 --- .../ibex_install_utils/tasks/mysql_tasks.py | 73 ------------------- .../truncate_database.bat | 23 ------ 3 files changed, 107 deletions(-) delete mode 100644 installation_and_upgrade/truncate_database.bat diff --git a/installation_and_upgrade/ibex_install_utils/install_tasks.py b/installation_and_upgrade/ibex_install_utils/install_tasks.py index bb7fb1cd..a55357c0 100644 --- a/installation_and_upgrade/ibex_install_utils/install_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/install_tasks.py @@ -233,8 +233,6 @@ def run_instrument_deploy_main(self) -> None: self._git_tasks.show_git_status() self._backup_tasks.backup_old_directories() self._backup_tasks.backup_checker() - self._mysql_tasks.backup_database() - self._mysql_tasks.truncate_database() self._server_tasks.install_ibex_server() self._system_tasks.create_virtual_envs() self._server_tasks.update_icp(self.icp_in_labview_modules()) @@ -261,11 +259,6 @@ def run_instrument_deploy_pre_stop(self) -> None: self._system_tasks.user_confirm_upgrade_type_on_machine("Client/Server Machine") self._server_tasks.save_motor_blocks_blockserver_to_file() - def run_truncate_database(self) -> None: - """Backup and truncate databases only""" - self._mysql_tasks.backup_database() - self._mysql_tasks.truncate_database() - def run_force_upgrade_mysql(self) -> None: """:key Do upgrade of mysql, with data dump. @@ -384,10 +377,6 @@ def run_vhd_post_install(self) -> None: UpgradeInstrument.remove_all_and_install_client_and_server, "install just the latest clean build of the server, client and genie_python", ), - "truncate_database": ( - UpgradeInstrument.run_truncate_database, - "backup and truncate the sql database on the instrument", - ), "update_icp": ( UpgradeInstrument.run_update_icp, "update isisicp on the instrument", diff --git a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py index 5a96bd8b..dbc7b870 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py @@ -84,31 +84,6 @@ def _get_mysql_backup_dir(self) -> str: os.mkdir(mysql_backup_dir) return mysql_backup_dir - @task("Truncate database") - def truncate_database(self) -> None: - """ - Truncate the message log, sample and alarms tables - """ - try: - mysql_bin_dir = self._get_mysql_dir() - - sql_command = ( - "truncate table msg_log.message;" - "truncate table archive.sample;truncate table alarm.pv" - ) - - RunProcess( - MYSQL_FILES_DIR, - "mysql.exe", - executable_directory=mysql_bin_dir, - prog_args=["-u", "root", "-p", "--execute", sql_command], - capture_pipes=False, - ).run() - - except ErrorInRun as ex: - self.prompt.prompt_and_raise_if_not_yes( - f"Unable to run mysql command, please truncate the database manually. Error is {ex}" - ) def _configure_mysql(self) -> None: """ @@ -411,54 +386,6 @@ def configure_mysql_for_vhd_post_install(self) -> None: sleep(5) # Time for service to start - @task("Backup database") - def backup_database(self) -> None: - """ - Backup the database - """ - mysql_bin_dir = self._get_mysql_dir() - result_file = os.path.join( - self._get_mysql_backup_dir(), - SQLDUMP_FILE_TEMPLATE.format(BaseTasks._today_date_for_filenames()), - ) - - # Get the number of tables to be backed up - sql_command = "show databases; use information_schema; show tables; SELECT FOUND_ROWS();" - count_tables = RunProcess( - MYSQL_FILES_DIR, - "mysql.exe", - executable_directory=mysql_bin_dir, - prog_args=["-u", "root", "-p", "--execute", sql_command], - capture_pipes=True, - capture_last_output=True, - ) - count_tables.run() - tables = ( - int(count_tables.captured_output) - 1 - ) # it seems to end up with an extra table when counting this. - - dump_command = [ - "-u", - "root", - "-p", - "--all-databases", - "--single-transaction", - "--verbose", - f"--result-file={result_file}", - ] - RunProcess( - MYSQL_FILES_DIR, - "mysqldump.exe", - executable_directory=mysql_bin_dir, - prog_args=dump_command, - capture_pipes=True, - progress_metric=[tables, "Retrieving table structure", "Backing up table "], - ).run() - - if os.path.getsize(result_file) < SMALLEST_PERMISSIBLE_MYSQL_DUMP_FILE_IN_BYTES: - self.prompt.prompt_and_raise_if_not_yes( - f"Dump file '{result_file}' seems to be small is it correct? " - ) def _backup_data(self) -> None: """ diff --git a/installation_and_upgrade/truncate_database.bat b/installation_and_upgrade/truncate_database.bat deleted file mode 100644 index 9e318159..00000000 --- a/installation_and_upgrade/truncate_database.bat +++ /dev/null @@ -1,23 +0,0 @@ -setlocal EnableDelayedExpansion -set "SOURCE=\\isis.cclrc.ac.uk\inst$\Kits$\CompGroup\ICP\Releases" -call "%~dp0install_or_update_uv.bat" -call "%~dp0set_up_venv.bat" -IF %errorlevel% neq 0 goto ERROR - -git --version - -IF %errorlevel% neq 0 ( - echo No installation of Git found on machine. Please download Git from https://git-scm.com/downloads before proceeding. - goto ERROR -) - -call python -u "%~dp0IBEX_upgrade.py" --release_dir "%SOURCE%" --release_suffix "%SUFFIX%" --confirm_step truncate_database -IF %errorlevel% neq 0 goto ERROR -call rmdir /s /q %UV_TEMP_VENV% - -exit /b 0 - -:ERROR -set errcode = %ERRORLEVEL% -call rmdir /s /q %UV_TEMP_VENV% -EXIT /b !errcode! From 37938b865487c75e6e0c4299d90731a9fc9ce6cf Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Tue, 14 Apr 2026 13:38:39 +0100 Subject: [PATCH 2/2] ruff --- .../ibex_install_utils/tasks/mysql_tasks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py index dbc7b870..c00b99ba 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/mysql_tasks.py @@ -7,7 +7,6 @@ from typing import Generator from ibex_install_utils.admin_runner import AdminCommandBuilder -from ibex_install_utils.exceptions import ErrorInRun from ibex_install_utils.logger import temporarily_disable_logging from ibex_install_utils.run_process import RunProcess from ibex_install_utils.software_dependency.mysql import MySQL @@ -84,7 +83,6 @@ def _get_mysql_backup_dir(self) -> str: os.mkdir(mysql_backup_dir) return mysql_backup_dir - def _configure_mysql(self) -> None: """ Copy mysql settings and run the MySQL configuration script @@ -386,7 +384,6 @@ def configure_mysql_for_vhd_post_install(self) -> None: sleep(5) # Time for service to start - def _backup_data(self) -> None: """ Backup the data for transfer. This dumps just the data not the schema.