restic formula rewrite and gitea updates
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
{% from "restic/map.jinja" import url with context %}
|
||||
|
||||
'download restic':
|
||||
cmd.run:
|
||||
- name: 'wget {{url}} -O - | bzip2 -cd > /bin/restic ; chmod +x /bin/restic'
|
||||
- unless: stat /bin/restic
|
||||
|
||||
/opt/restic_backups.sh:
|
||||
file.managed:
|
||||
- source: 'salt://restic/files/restic_backup.sh.jinja'
|
||||
- template: jinja
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 0700
|
||||
cron.present:
|
||||
- minute: random
|
||||
- hour: 4
|
||||
- dayweek: 0
|
||||
8
restic/files/backup.sh.jinja
Normal file
8
restic/files/backup.sh.jinja
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
source /opt/restic/env.sh
|
||||
touch /var/log/restic/backup.log
|
||||
chmod 600 /var/log/restic/backup.log
|
||||
(
|
||||
date
|
||||
{{ '\n'.join(salt.pillar.get("restic:client:cmds")) | indent(2) }}
|
||||
) 2>&1 | tee -a /var/log/restic/backup.log
|
||||
4
restic/files/env.sh.jinja
Normal file
4
restic/files/env.sh.jinja
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
{%- for var, val in salt.pillar.get("restic:client:environ").items() %}
|
||||
export {{ var }}={{ val }}
|
||||
{%- endfor %}
|
||||
18
restic/files/install.sh.jinja
Normal file
18
restic/files/install.sh.jinja
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
{% set arch = 'arm' salt.grains.get(cpuarch).startswith('arm') else 'amd64' %}
|
||||
|
||||
if test -z "$RESTIC_VERSION"; then
|
||||
echo "RESTIC_VERSION is not defined"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
URL="https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_{{ arch }}.bz2"
|
||||
|
||||
wget --quiet "${URL}" -O - | bzip2 -cd > /bin/restic.tmp
|
||||
if [ $? -eq 0 ]; then
|
||||
chmod +x /bin/restic.tmp
|
||||
mv /bin/restic.tmp /bin/restic
|
||||
else
|
||||
rm -f /bin/restic.tmp
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
export HOME=/root
|
||||
export RESTIC_PASSWORD={{ salt.pillar.get('restic:pass') }}
|
||||
export RESTIC_REPOSITORY={{ salt.pillar.get('restic:repo') }}
|
||||
restic backup --tag files {{ salt.pillar.get('restic:files') }}
|
||||
{% if salt.pillar.get('restic:mysql', False) -%}
|
||||
mysqldump --all-databases | restic backup --stdin --stdin-filename /all_databases.sql --tag mysql
|
||||
{% endif -%}
|
||||
restic forget --keep-last 4 --tag mysql --prune
|
||||
{% if salt.pillar.get('restic:mysql', False) -%}
|
||||
restic forget --keep-last 4 --tag files --prune
|
||||
{% endif -%}
|
||||
74
restic/init.sls
Normal file
74
restic/init.sls
Normal file
@@ -0,0 +1,74 @@
|
||||
{% for client in salt.pillar.get("restic:server:clients", []) %}
|
||||
restic-{{ client }}:
|
||||
user.present:
|
||||
- home: {{ salt.pillar.get("restic:server:mount") }}/{{ client }}
|
||||
- createhome: true
|
||||
- system: true
|
||||
{% endfor %}
|
||||
|
||||
{% if salt.pillar.get("restic:client", None) is not none %}
|
||||
{% if salt.pillar.get("restic:client:install", True)%}
|
||||
'download restic':
|
||||
cmd.script:
|
||||
- shell: /bin/bash
|
||||
- source: salt://restic/files/install.sh.jinja
|
||||
- templates: jinja
|
||||
- unless: "/bin/restic version | grep 'restic 0.16.2 '"
|
||||
- env:
|
||||
- RESTIC_VERSION: 0.16.2
|
||||
{% endif %}
|
||||
|
||||
/etc/logrotate.d/restic-backup:
|
||||
file.managed:
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
- contents: |
|
||||
/var/log/restic/backup.log {
|
||||
monthly
|
||||
rotate 3
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
create 600 root root
|
||||
}
|
||||
|
||||
/opt/restic:
|
||||
file.directory:
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 700
|
||||
|
||||
/opt/restic/env.sh:
|
||||
file.managed:
|
||||
- source: 'salt://restic/files/env.sh.jinja'
|
||||
- template: jinja
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 700
|
||||
- require:
|
||||
- file: /opt/restic
|
||||
|
||||
/opt/restic/backup.sh:
|
||||
file.managed:
|
||||
- source: 'salt://restic/files/backup.sh.jinja'
|
||||
- template: jinja
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 700
|
||||
- require:
|
||||
- file: /opt/restic
|
||||
"/opt/restic/backup.sh 2>&1 >/dev/null":
|
||||
cron.present:
|
||||
- identifier: restic backup
|
||||
- minute: random
|
||||
- hour: 4
|
||||
- dayweek: 0
|
||||
|
||||
/var/log/restic:
|
||||
file.directory:
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 700
|
||||
|
||||
{% endif %}
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
{% if salt.grains.get('cpuarch').startswith('arm') %}
|
||||
{% set url = 'https://github.com/restic/restic/releases/download/v0.9.6/restic_0.9.6_linux_arm.bz2' %}
|
||||
{% else %}
|
||||
{% set url = 'https://github.com/restic/restic/releases/download/v0.9.6/restic_0.9.6_linux_amd64.bz2' %}
|
||||
{% endif %}
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
restic-vps:
|
||||
user.present:
|
||||
- home: /mnt/bak1/restic-vps
|
||||
- uid: 1002
|
||||
- gid: 1002
|
||||
|
||||
Reference in New Issue
Block a user