Skip to content

Instantly share code, notes, and snippets.

@viq
Last active August 12, 2020 12:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viq/06658a5ee1782885e13253cd543539c2 to your computer and use it in GitHub Desktop.
Save viq/06658a5ee1782885e13253cd543539c2 to your computer and use it in GitHub Desktop.
Serialization doesn't seem to maintain the structure
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
borg:
backup_key: '/root/.ssh/backup_key'
borgmatic:
location:
source_directories:
- /etc
- /home
retention:
prefix: "{fqdn}-"
keep_minutely: 60
keep_hourly: 48
keep_daily: 7
keep_weekly: 5
keep_monthly: 6
keep_yearly: 1
consistency:
prefix: "{fqdn}-"
exclude_patterns:
- '*.pyc'
- '*.swp'
- '~/*/.cache'
- '/var/cron/log*'
{% from "borg/map.jinja" import borg with context %}
backup ssh key:
cmd.run:
- name: 'ssh-keygen -q -t ed25519 -C "{{ salt.grains.get('id') }} backup key" -f {{ borg.backup_key}} -N ""'
- creates: {{ borg.backup_key }}
module.wait:
- mine.send:
- ssh_backup_key
- mine_function: ssh.user.keys
- user: root
- pubfile: '{{borg.backup_key}}.pub'
- prvfile: False
- watch:
- cmd: backup ssh key
borg backup programs:
pkg.installed:
- pkgs:
- {{borg.borg_package}}
- {{borg.borgmatic_package}}
borgmatic configuration test:
file.serialize:
- name: /tmp/bm-test.yaml
- formatter: yaml
- dataset: {{borg.borgmatic}}
# -*- coding: utf-8 -*-
# vim: ft=jinja
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{#- Start imports as #}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %}
{#- Retrieve the config dict only once #}
{%- set _config = salt['config.get'](tplroot, default={}) %}
{%- set defaults = salt['grains.filter_by'](
default_settings,
default=tplroot,
merge=salt['grains.filter_by'](
_config,
default='lookup'
)
)
%}
{%- set defaults = salt['grains.filter_by'](
default_settings,
default=tplroot,
merge=salt['grains.filter_by'](
osarchmap,
grain='osarch',
merge=salt['grains.filter_by'](
osfamilymap,
grain='os_family',
merge=salt['grains.filter_by'](
_config,
default='lookup'
)
)
)
)
%}
{%- set config = salt['grains.filter_by'](
{'defaults': defaults},
default='defaults',
merge=_config
)
%}
{% set borg = config %}
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Setup variables using grains['osarch'] based logic.
# You just need to add the key:values for an `osarch` that differ
# from `defaults.yaml`.
# Only add an `osarch` which is/will be supported by the formula.
#
# If you do not need to provide defaults via the `osarch` grain,
# you will need to provide at least an empty dict in this file, e.g.
# osarch: {}
---
amd64:
arch: amd64
x86_64:
arch: amd64
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Setup variables using grains['os_family'] based logic.
# You just need to add the key:values for an `os_family` that differ
# from `defaults.yaml` + `osarch.yaml`.
# Only add an `os_family` which is/will be supported by the formula.
#
# If you do not need to provide defaults via the `os_family` grain,
# you will need to provide at least an empty dict in this file, e.g.
# osfamilymap: {}
---
FreeBSD:
repo_base: '/export/backup/borg'
zfs_base: 'backups/borg'
user_shell: '/bin/sh'
borg_package: 'py37-borgbackup'
borgmatic_package: 'py37-borgmatic'
Arch:
repo_base: '/var/lib/borg/repos'
user_shell: '/bin/bash'
borg_package: 'borg'
borgmatic_package: 'borgmatic'
OpenBSD:
borg_package: 'borgbackup'
borgmatic_package: 'borgmatic'
borgmatic:
location:
source_directories:
- /etc
- /home
- /var/backups
- /var/db/pkg
- /var/unbound
- /var/nsd
consistency:
prefix: '{fqdn}-'
exclude_patterns:
- '*.pyc'
- '*.swp'
- ~/*/.cache
- /var/cron/log*
location:
source_directories:
- /etc
- /home
- /var/backups
- /var/db/pkg
- /var/unbound
- /var/nsd
retention:
keep_daily: 7
keep_hourly: 48
keep_minutely: 60
keep_monthly: 6
keep_weekly: 5
keep_yearly: 1
prefix: '{fqdn}-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment