2020-08-27 18:01:08 +02:00
|
|
|
#!{{ backup_client_shell }}
|
2020-08-30 12:47:40 +02:00
|
|
|
export HOME={{ backup_client_user_home }}
|
2020-07-25 15:06:58 +02:00
|
|
|
{% for backup_serv in groups['backup_server'] %}
|
|
|
|
|
|
|
|
# Check if {{ backup_serv }} is a known host
|
|
|
|
grep {{ backup_serv }} ~/.ssh/known_hosts &> /dev/null
|
|
|
|
if [ ! $? -eq 0 ]; then
|
|
|
|
ssh-keygen -F {{ backup_serv }} || ssh-keyscan {{ backup_serv }} >>~/.ssh/known_hosts
|
|
|
|
fi
|
|
|
|
|
2020-08-27 18:01:08 +02:00
|
|
|
{{ backup_client_borgbackup_bin }} list backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) &>/dev/null
|
2020-07-25 15:06:58 +02:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
ssh backup-$(hostname -s)@{{ backup_serv }} mkdir -p {{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) -m 0700
|
|
|
|
export BORG_PASSPHRASE=""
|
2020-08-27 18:01:08 +02:00
|
|
|
{{ backup_client_borgbackup_bin }} init --encryption=repokey backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s)
|
2020-07-25 15:06:58 +02:00
|
|
|
fi
|
|
|
|
|
2020-08-27 18:01:08 +02:00
|
|
|
{{ backup_client_borgbackup_bin }} prune -v backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s) --keep-daily=7 --keep-weekly=4 --keep-monthly=1
|
|
|
|
{{ backup_client_borgbackup_bin }} create --info --stats --compression {{ backup_client_compression_param }} backup-$(hostname -s)@{{ backup_serv }}:{{ hostvars[backup_serv]['backup_folder'] }}/$(hostname -s)::$(date +%F) $(find {{ backup_client_folders_to_backup }} -maxdepth 1 -type d | grep -Ev '^/$|^/tmp|^/lost\+found|^/run|^/proc|^/dev|^/sys' | tr '\n' ' ')
|
2020-07-25 15:06:58 +02:00
|
|
|
{% endfor %}
|