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