1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-10-31 18:30:33 +03:00
Files
mariadb-columnstore-engine/cmapi/cmapi_server/managers/backup_restore.py
mariadb-AlanMologorsky a76e153a1d feat(upgrade): MCOL-6028 upgrade MVP with repo-managed flow, prechecks, and other enhancements
Implements the initial upgrade capability across CMAPI and the CLI, including
repository setup, package operations, environment prechecks, and coordinated
cluster steps with progress reporting.

Details:
- CMAPI upgrade manager:
  - Add `cmapi/cmapi_server/managers/upgrade/` modules:
    - `repo.py`, `packages.py`, `preinstall.py`, `upgrade.py`, `utils.py` and `__init__.py`
  - Extend endpoints and routing to expose upgrade operations and status:
    - `cmapi_server/controllers/{endpoints.py, dispatcher.py, api_clients.py}`
    - `cmapi_server/managers/{application.py, process.py}`
    - Add improved constants and helpers for upgrade flow
- Backup/restore and safety:
  - Add `cmapi_server/managers/backup_restore.py`
  - Fix pre-upgrade backup regressions (due to `mcs_backup_manager.sh 3.17 changes`)
  - Improve cluster version validation; add `ignore_missmatch` override
- CLI enhancements:
  - Progress UI and richer feedback (`mcs_cluster_tool/tools_commands.py`, `README.md`, `mcs.1`)
  - Add steps to start MDB and start MCS during/after upgrade
  - Improved error surfacing for version validation
- Platform and packaging:
  - Ubuntu and Rocky Linux support
  - RHEL/DNF dry-run support
  - Distro detection and platform-dependent logic hardened
  - Logging improvements
- Updater service:
  - Add `cmapi/updater/cmapi_updater.service.template` and `cmapi_updater.sh` to make CMAPI update itself
- Docs:
  - Update mcs cli README and mcs.1 man file
  - Add `cmapi/updater/README.md`
2025-09-30 18:48:32 +04:00

116 lines
3.6 KiB
Python

import logging
import glob
import shutil
import os
from datetime import datetime
from cmapi_server.exceptions import CMAPIBasicError
from cmapi_server.process_dispatchers.base import BaseDispatcher
from cmapi_server.constants import MCS_BACKUP_MANAGER_SH
class BackupRestoreManager:
@classmethod
def backup_dbrm(cls, args: dict) -> None:
"""Make DBRM backup.
:raises CMAPIBasicError: If dbrm backup is unsuccesfull.
"""
cmd: str = (
f'{MCS_BACKUP_MANAGER_SH} dbrm_backup '
f'{" ".join([f"{k} {v}" if v else k for k,v in args.items()])}'
)
success, cmd_output = BaseDispatcher.exec_command(cmd)
if not success:
err_message: str = ''
if not cmd_output:
err_message = f'Can\'t start DBRM backup using cmd: "{cmd}"'
logging.error(err_message, exc_info=True)
else:
logging.error(err_message)
raise CMAPIBasicError(err_message)
class PreUpgradeBackupRestoreManager(BackupRestoreManager):
@classmethod
def backup_dbrm(cls) -> None: #pylint: disable=arguments-differ
"""PreUpgrade dbrm backup.
:raises CMAPIBasicError: If dbrm backup is unsuccesfull.
"""
args = {
'-r': '9999',
'-nb': 'preupgrade_dbrm_backup',
'--quiet': '',
'--skip-locks': ''
}
super().backup_dbrm(args)
@classmethod
def _copy_files(cls, source_pattern: str, destination_dir: str):
"""Copy files using pattern path to a given destination.
:param source_pattern: source pattern could be just a str path
:type source_pattern: str
:param destination_dir: destination dir
:type destination_dir: str
"""
files = glob.glob(source_pattern)
if not files:
logging.warning(f'No files matched: {source_pattern}')
return
for file_path in files:
try:
logging.debug(f'Copying: {file_path} -> {destination_dir}')
shutil.copy(file_path, destination_dir)
except Exception:
logging.warning(
f'Failed to copy {file_path}',
exc_info=True
)
@classmethod
def backup_configs(cls, distro_name: str):
"""Backup config files.
:param distro_name: node distro name
:type distro_name: str
"""
timestamp = datetime.now().strftime('%m-%d-%Y-%H%M')
pre_upgrade_config_directory = (
f'/tmp/preupgrade-configurations-{timestamp}'
)
os.makedirs(pre_upgrade_config_directory, exist_ok=True)
cls._copy_files(
'/etc/columnstore/Columnstore.xml', pre_upgrade_config_directory
)
cls._copy_files(
'/etc/columnstore/storagemanager.cnf', pre_upgrade_config_directory
)
cls._copy_files(
'/etc/columnstore/cmapi_server.conf', pre_upgrade_config_directory
)
if distro_name in ['centos', 'rhel', 'rocky', 'almalinux']:
cls._copy_files(
'/etc/my.cnf.d/server.cnf', pre_upgrade_config_directory
)
elif distro_name in ['ubuntu', 'debian']:
cls._copy_files(
'/etc/mysql/mariadb.conf.d/*server.cnf',
pre_upgrade_config_directory
)
else:
logging.error(f'Unknown distro: {distro_name}')
@staticmethod
def restore_dbrm():
#TODO: implement restore logic
pass
@staticmethod
def restore_configs():
pass