From 046de339c8faf62c032a009975ab8f076785485a Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 7 Feb 2024 22:02:04 +0100 Subject: [PATCH] added clickhouse-backup state --- states/clickhouse-backup/config.sls | 14 +++++++ states/clickhouse-backup/defaults.yaml | 28 ++++++++++++++ states/clickhouse-backup/init.sls | 4 ++ states/clickhouse-backup/install.sls | 38 +++++++++++++++++++ states/clickhouse-backup/kernelmap.yaml | 3 ++ states/clickhouse-backup/map.jinja | 14 +++++++ states/clickhouse-backup/osarchmap.yaml | 24 ++++++++++++ .../clickhouse-backup/templates/config.yml.j2 | 4 ++ 8 files changed, 129 insertions(+) create mode 100644 states/clickhouse-backup/config.sls create mode 100644 states/clickhouse-backup/defaults.yaml create mode 100644 states/clickhouse-backup/init.sls create mode 100644 states/clickhouse-backup/install.sls create mode 100644 states/clickhouse-backup/kernelmap.yaml create mode 100644 states/clickhouse-backup/map.jinja create mode 100644 states/clickhouse-backup/osarchmap.yaml create mode 100644 states/clickhouse-backup/templates/config.yml.j2 diff --git a/states/clickhouse-backup/config.sls b/states/clickhouse-backup/config.sls new file mode 100644 index 0000000..306176a --- /dev/null +++ b/states/clickhouse-backup/config.sls @@ -0,0 +1,14 @@ +--- +{%- from "clickhouse-backup/map.jinja" import clickhousebackup with context %} +clickhouse-backup-config-dir: + file.directory: + - name: {{ clickhousebackup.config_dir }} + - user: root + - group: root + - mode: 700 + +clickhouse-backup-config-file: + file.managed: + - name: {{ clickhousebackup.config_dir }}/config.yml + - source: salt://clickhouse-backup/templates/config.yml.j2 + - template: jinja diff --git a/states/clickhouse-backup/defaults.yaml b/states/clickhouse-backup/defaults.yaml new file mode 100644 index 0000000..0b7191e --- /dev/null +++ b/states/clickhouse-backup/defaults.yaml @@ -0,0 +1,28 @@ +--- +clickhouse-backup: + enabled: true + release_dir: /usr/local/apps/releases + install_dir: /usr/local/apps + mirror: https://github.com/Altinity/clickhouse-backup/releases/download + config_dir: /etc/clickhouse-backup + version: 2.4.14 + os: linux + arch: x64 + config: + general: + disable_progress_bar: false + backups_to_keep_local: 3 + backups_to_keep_remote: 7 + #remote_storage: custom + #use_embedded_backup_restore: true + use_resumable_state: false + restore_as_attach: false + restore_database_mapping: {} + clickhouse: + host: localhost + port: 9000 + username: default + password: "" + sync_replicated_tables: true + timeout: 5s + restart_command: "sql:SYSTEM RELOAD USERS; sql:SYSTEM RELOAD CONFIG; sql:SYSTEM SHUTDOWN" diff --git a/states/clickhouse-backup/init.sls b/states/clickhouse-backup/init.sls new file mode 100644 index 0000000..d507940 --- /dev/null +++ b/states/clickhouse-backup/init.sls @@ -0,0 +1,4 @@ +--- +include: + - .install + - .config diff --git a/states/clickhouse-backup/install.sls b/states/clickhouse-backup/install.sls new file mode 100644 index 0000000..357b0ba --- /dev/null +++ b/states/clickhouse-backup/install.sls @@ -0,0 +1,38 @@ +--- +{%- from "clickhouse-backup/map.jinja" import clickhousebackup with context %} +clickhouse-backup-archive-extract: + archive.extracted: + - name: {{ clickhousebackup.release_dir }}/clickhouse-backup-{{ clickhousebackup.version }} + - source: {{ clickhousebackup.mirror }}/v{{ clickhousebackup.version }}/clickhouse-backup-{{ clickhousebackup.os }}-{{ clickhousebackup.arch }}.tar.gz + - enforce_toplevel: false + - options: > + --strip 3 + - skip_verify: true + - archive_format: tar + - if_missing: {{ clickhousebackup.release_dir }}/clickhouse-backup-{{ clickhousebackup.version }}/clickhouse-backup + +clickhouse-backup-bin-perm: + file.managed: + - name: {{ clickhousebackup.release_dir }}/clickhouse-backup-{{ clickhousebackup.version }}/clickhouse-backup + - user: root + - group: root + - replace: False + - require: + - archive: clickhouse-backup-archive-extract + +clickhouse-backup-bin-symlink: + file.symlink: + - name: /usr/local/sbin/clickhouse-backup + - target: {{ clickhousebackup.release_dir }}/clickhouse-backup-{{ clickhousebackup.version }}/clickhouse-backup + - user: root + - group: root + - mode: 0755 + - force: true + - require: + - archive: clickhouse-backup-archive-extract + +clickhouse-backup-cleanup: + software.cleanup: + - name: clickhouse-backup + - path: {{ clickhousebackup.release_dir }} + - version: "{{ clickhousebackup.version }}" diff --git a/states/clickhouse-backup/kernelmap.yaml b/states/clickhouse-backup/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/clickhouse-backup/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/clickhouse-backup/map.jinja b/states/clickhouse-backup/map.jinja new file mode 100644 index 0000000..f0f0775 --- /dev/null +++ b/states/clickhouse-backup/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "clickhouse-backup/defaults.yaml" as default_settings -%} + +{%- import_yaml "clickhouse-backup/kernelmap.yaml" as kernelmap -%} +{%- import_yaml "clickhouse-backup/osarchmap.yaml" as osarchmap -%} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='clickhouse-backup', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set clickhousebackup = salt['pillar.get']('clickhouse-backup', default=defaults, merge=True) -%} diff --git a/states/clickhouse-backup/osarchmap.yaml b/states/clickhouse-backup/osarchmap.yaml new file mode 100644 index 0000000..05f0f25 --- /dev/null +++ b/states/clickhouse-backup/osarchmap.yaml @@ -0,0 +1,24 @@ +--- +amd64: + arch: "amd64" + +x86_64: + arch: "amd64" + +386: + arch: "386" + +arm64: + arch: "arm64" + +aarch64: + arch: "arm64" + +armv6l: + arch: "arm" + +armv7l: + arch: "arm" + +armhf: + arch: "arm" diff --git a/states/clickhouse-backup/templates/config.yml.j2 b/states/clickhouse-backup/templates/config.yml.j2 new file mode 100644 index 0000000..44f7311 --- /dev/null +++ b/states/clickhouse-backup/templates/config.yml.j2 @@ -0,0 +1,4 @@ +{%- from "clickhouse-backup/map.jinja" import clickhousebackup with context -%} +# {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +--- +{{ clickhousebackup.config|yaml(False) }}