backup_and_restore_actions.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from materialize.mzcompose.composition import Composition
  10. from materialize.mzcompose.services.materialized import Materialized
  11. from materialize.zippy.crdb_capabilities import CockroachIsRunning
  12. from materialize.zippy.framework import Action, Capability, State
  13. from materialize.zippy.mz_capabilities import MzIsRunning
  14. class BackupAndRestore(Action):
  15. @classmethod
  16. def requires(cls) -> set[type[Capability]]:
  17. return {MzIsRunning, CockroachIsRunning}
  18. def run(self, c: Composition, state: State) -> None:
  19. # TODO: Support and test azurite backups
  20. if c.blob_store() == "azurite":
  21. return
  22. # Required because of database-issues#6880
  23. c.kill("storaged")
  24. c.backup()
  25. with c.override(
  26. Materialized(
  27. name=state.mz_service,
  28. external_blob_store=True,
  29. blob_store_is_azure=c.blob_store() == "azurite",
  30. external_metadata_store=True,
  31. deploy_generation=state.deploy_generation,
  32. system_parameter_defaults=state.system_parameter_defaults,
  33. sanity_restart=False,
  34. restart="on-failure",
  35. metadata_store="cockroach",
  36. default_replication_factor=2,
  37. )
  38. ):
  39. c.restore(state.mz_service)
  40. c.up("storaged")