From b17c4b27094a6b767ec844e530cbaf6535cdad1d Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Sun, 5 Feb 2023 16:34:01 +0100 Subject: [PATCH] Add duplicity --- main.yml | 55 ++++++++++++++++--------------- roles/duplicity/files/backup.sh | 24 ++++++++++++++ roles/duplicity/tasks/account.yml | 9 +++++ roles/duplicity/tasks/cron.yml | 18 ++++++++++ roles/duplicity/tasks/install.yml | 12 +++++++ roles/duplicity/tasks/main.yml | 6 ++++ 6 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 roles/duplicity/files/backup.sh create mode 100644 roles/duplicity/tasks/account.yml create mode 100644 roles/duplicity/tasks/cron.yml create mode 100644 roles/duplicity/tasks/install.yml create mode 100644 roles/duplicity/tasks/main.yml diff --git a/main.yml b/main.yml index 866d5af..ae40cbf 100644 --- a/main.yml +++ b/main.yml @@ -1,31 +1,32 @@ --- -- hosts: prusa - roles: - - ssh - - octoprint - - ubuntu - -- hosts: docker_cluster - roles: - - node_explorer - - ssh - - docker-cluster - - ubuntu - -- hosts: raspberry - roles: - - i2c-clock - -- hosts: router.lan - roles: - - router - -- hosts: remote_server - roles: - - docker +#- hosts: prusa +# roles: +# - ssh +# - octoprint +# - ubuntu +# +#- hosts: docker_cluster +# roles: +# - node_explorer +# - ssh +# - docker-cluster +# - ubuntu +# +#- hosts: raspberry +# roles: +# - i2c-clock +# +#- hosts: router.lan +# roles: +# - router +# +#- hosts: remote_server +# roles: +# - docker - hosts: uatu.lan roles: - - ssh - - ubuntu - - docker \ No newline at end of file +# - ssh +# - ubuntu +# - docker + - duplicity \ No newline at end of file diff --git a/roles/duplicity/files/backup.sh b/roles/duplicity/files/backup.sh new file mode 100644 index 0000000..a99a449 --- /dev/null +++ b/roles/duplicity/files/backup.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +source /home/duplicity/email-settings.sh + +MAX_TIME="3M" +FULL_BACKUP_EVERY="1M" +SOURCE="/mnt/MAIN" +DESTINATION="onedrive://duplicity/nas" + +LOG="/home/duplicity/backup.log" + +rm $LOG +duplicity remove-older-than $MAX_TIME $DESTINATION >> $LOG +duplicity --full-if-older-than $FULL_BACKUP_EVERY $SOURCE $DESTINATION >> $LOG + +sendemail \ + -f "$EMAIL_SENDER" \ + -t "$EMAIL_RECEIPIENT" \ + -u "Duplicity backup log" \ + -message-file=$LOG \ + -s "$EMAIL_SERVER" \ + -xu "$EMAIL_USER" \ + -xp "$EMAIL_PASSWORD" \ + -o "tls=$EMAIL_TLS" diff --git a/roles/duplicity/tasks/account.yml b/roles/duplicity/tasks/account.yml new file mode 100644 index 0000000..1492fa0 --- /dev/null +++ b/roles/duplicity/tasks/account.yml @@ -0,0 +1,9 @@ +--- +- name: create duplicity account + become: yes + user: + name: duplicity + comment: Duplicity account + system: yes + password_lock: yes + home: /home/duplicity diff --git a/roles/duplicity/tasks/cron.yml b/roles/duplicity/tasks/cron.yml new file mode 100644 index 0000000..a107fd7 --- /dev/null +++ b/roles/duplicity/tasks/cron.yml @@ -0,0 +1,18 @@ +--- +- name: copy configuration + become: yes + copy: + src: backup.sh + dest: /home/duplicity/backup.sh + mode: '0750' + owner: duplicity + group: duplicity + +- name: Create cron job for autobackup + become: yes + ansible.builtin.cron: + user: duplicity + name: "Backup" + minute: "0" + hour: "3" + job: "/home/duplicity/backup.sh" \ No newline at end of file diff --git a/roles/duplicity/tasks/install.yml b/roles/duplicity/tasks/install.yml new file mode 100644 index 0000000..28ee0bd --- /dev/null +++ b/roles/duplicity/tasks/install.yml @@ -0,0 +1,12 @@ +--- +- become: yes + block: + - name: install needed packages + apt: + update_cache: yes + pkg: + - duplicity + - python3-requests-oauthlib + - sendemail + - libio-socket-ssl-perl + - libnet-ssleay-perl \ No newline at end of file diff --git a/roles/duplicity/tasks/main.yml b/roles/duplicity/tasks/main.yml new file mode 100644 index 0000000..5bfc90b --- /dev/null +++ b/roles/duplicity/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- import_tasks: account.yml + +- import_tasks: install.yml + +- import_tasks: cron.yml