Fix template extension, add borg backup install

This commit is contained in:
Tomislav Kopić 2024-02-10 12:09:14 +01:00
parent f0f9df53a3
commit 9691d7dc5d
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,31 @@
---
- hosts: all
become: yes
vars:
borg.repo.path: /var/backup/backup.borg/
borg.repo.encryption: none
tasks:
- name: "Install borg backup"
apt:
name: borgbackup
state: latest
- name: "Create backup repository"
ansible.builtin.command: borg init -e {{borg.repo.encryption}} {{borg.repo.path}}
args:
creates: {{borg.repo.path}}
- name: "Configure backup script"
ansible.builtin.copy:
src: ../templates/borgbackup.j2
dest: /opt/borgbackup.sh
owner: root
group: root
mode: '744'
- name: "Configure cronjob"
ansible.builtin.cron:
name: "Borg backup"
minute: "0"
hour: "1"
job: "/opt/borgbackup.sh"

15
templates/borgbackup.j2 Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# Borg repo location
REPOSITORY={{borg.repo.path}}
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/{{borg.repo.path}}
echo "`date +[%F/%T]` Starting the backup"
# Create backup
borg create -v --compression lzma,6 --stats $REPOSITORY::$(date +%Y-%m-%d-%H:%M) /etc/ /var/spool/ --exclude=*.log
# Clean old backups
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
exit

View File

@ -0,0 +1,20 @@
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogType=file
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
DebugLevel=2
Server={{ zabbix_server }}
ListenPort=10050
ListenIP={{ ansible_default_ipv4.address }}
ServerActive={{ zabbix_server }}
Hostname={{ ansible_hostname }}
HostMetadata={{ host_meta }}
RefreshActiveChecks=300
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
ControlSocket=/tmp/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf
TLSAccept=psk
TLSConnect=psk
TLSPSKIdentity={{ psk_id }}
TLSPSKFile=/etc/zabbix/key.psk
UserParameter=get.sensors.data,/usr/bin/sensors -j