瀏覽代碼

salt master / minion backup

PROD-16375

Change-Id: I758d38701cdf0e1cc6fa99c38192de2f9052468c
pull/70/merge
Jiri Broulik 7 年之前
父節點
當前提交
b347eaf066
共有 6 個文件被更改,包括 68 次插入8 次删除
  1. +1
    -0
      salt/files/restore_master.sh
  2. +11
    -0
      salt/files/restore_minion.sh
  3. +5
    -6
      salt/master/restore.sls
  4. +10
    -2
      salt/meta/backupninja.yml
  5. +33
    -0
      salt/minion/restore.sls
  6. +8
    -0
      tests/pillar/minion_backup.sls

salt/files/restore.sh → salt/files/restore_master.sh 查看文件

{%- from "salt/map.jinja" import master with context %} {%- from "salt/map.jinja" import master with context %}


{%- if master.initial_data is defined %} {%- if master.initial_data is defined %}
mkdir -p /etc/salt/pki.bak
mv /etc/salt/pki/* /etc/salt/pki.bak mv /etc/salt/pki/* /etc/salt/pki.bak
scp -r backupninja@{{ master.initial_data.source }}:/srv/backupninja/{{ master.initial_data.host }}/etc/salt/pki/pki.0/* /etc/salt/pki scp -r backupninja@{{ master.initial_data.source }}:/srv/backupninja/{{ master.initial_data.host }}/etc/salt/pki/pki.0/* /etc/salt/pki
{%- if master.pillar.engine == 'reclass' or (master.pillar.engine == 'composite' and master.pillar.reclass is defined) %} {%- if master.pillar.engine == 'reclass' or (master.pillar.engine == 'composite' and master.pillar.reclass is defined) %}

+ 11
- 0
salt/files/restore_minion.sh 查看文件

#!/bin/sh
{%- from "salt/map.jinja" import minion with context %}

{%- if minion.ca is defined %}
{%- if minion.initial_data is defined %}
mkdir -p /etc/pki/pki_ca.bak
mkdir -p /etc/pki/ca
mv /etc/pki/ca/* /etc/pki/pki_ca.bak
scp -r backupninja@{{ minion.initial_data.source }}:/srv/backupninja/{{ minion.initial_data.host }}/etc/pki/ca/ca.0/* /etc/pki/ca
{%- endif %}
{%- endif %}

+ 5
- 6
salt/master/restore.sls 查看文件



{%- if master.initial_data is defined %} {%- if master.initial_data is defined %}


/srv/salt/restore.sh:
file:
- managed
- source: salt://salt/files/restore.sh
/srv/salt/restore_master.sh:
file.managed:
- source: salt://salt/files/restore_master.sh
- mode: 700 - mode: 700
- template: jinja - template: jinja


salt_master_restore_state: salt_master_restore_state:
cmd.run: cmd.run:
- name: /srv/salt/restore.sh
- name: /srv/salt/restore_master.sh
- unless: "test -e /srv/salt/master-restored" - unless: "test -e /srv/salt/master-restored"
- cwd: /root - cwd: /root
- require: - require:
- file: /srv/salt/restore.sh
- file: /srv/salt/restore_master.sh


salt_master_restore_completed: salt_master_restore_completed:
file.managed: file.managed:

+ 10
- 2
salt/meta/backupninja.yml 查看文件

{%- if pillar.salt.master is defined %}
{%- from "salt/map.jinja" import master with context %}
{%- if pillar.salt is defined %}
{%- if pillar.salt.get('master', {}).get('enabled', False) or (pillar.salt.get('minion', {}).get('enabled', False) and pillar.salt.get('minion', {}).ca is defined) %}
{%- from "salt/map.jinja" import master, minion with context %}
backup: backup:
salt: salt:
{%- if master.get('backup', False) %} {%- if master.get('backup', False) %}
- /srv/salt/reclass/nodes/_generated - /srv/salt/reclass/nodes/_generated
{%- endif %} {%- endif %}
- /etc/salt/pki - /etc/salt/pki
{%- if minion.get('backup', False) %}
- /etc/pki/ca
{%- endif %}
{%- elif minion.get('backup', False) %}
fs_includes:
- /etc/pki/ca
{%- else %} {%- else %}
fs_includes: [] fs_includes: []
{%- endif %} {%- endif %}
fs_excludes: [] fs_excludes: []
{%- endif %} {%- endif %}
{%- endif %}

+ 33
- 0
salt/minion/restore.sls 查看文件

{%- from "salt/map.jinja" import minion with context %}
{%- if minion.enabled %}

{%- if minion.ca is defined %}

{%- if minion.initial_data is defined %}

/srv/salt/restore_minion.sh:
file.managed:
- source: salt://salt/files/restore_minion.sh
- mode: 700
- template: jinja

salt_minion_restore_state:
cmd.run:
- name: /srv/salt/restore_minion.sh
- unless: "test -e /srv/salt/minion-restored"
- cwd: /root
- require:
- file: /srv/salt/restore_minion.sh

salt_minion_restore_completed:
file.managed:
- name: /srv/salt/minion-restored
- source: {}
- require:
- cmd: salt_minion_restore_state

{%- endif %}

{%- endif %}

{%- endif %}

+ 8
- 0
tests/pillar/minion_backup.sls 查看文件

salt:
minion:
enabled: true
backup: true
initial_data:
engine: backupninja
source: backup-node-host
host: original-salt-master-id

Loading…
取消
儲存