Commit 402ff599 authored by Nicolas Steinmetz's avatar Nicolas Steinmetz
Browse files

feat(openhab): add backup

parent 1bf45f71
---
openhab_zulu_package: zulu11.43.100-ca-jdk11.0.9.1-linux_aarch32hf
openhab_use_zwave: no
openhab_deb_version: 3.0.0-1
\ No newline at end of file
openhab_deb_version: 3.0.1-2
openhab_swift_container: ""
#openhab_timer: ""
swift_upload: false
swift_delete: false
OS_AUTH_URL: ""
OS_IDENTITY_API_VERSION: ""
OS_USER_DOMAIN_NAME: Default
OS_PROJECT_DOMAIN_NAME: Default
OS_TENANT_ID: ""
OS_TENANT_NAME: ""
OS_REGION_NAME: ""
OS_USERNAME: ""
OS_PASSWORD: ""
......@@ -3,4 +3,10 @@
systemd:
name: openhab
daemon_reload: yes
state: restarted
\ No newline at end of file
state: restarted
- name: restart openhab-backup-timer
systemd:
name: openhab-backup.timer
state: restarted
daemon_reload: yes
\ No newline at end of file
......@@ -98,4 +98,39 @@
name: openhab
state: started
enabled: yes
daemon_reload: yes
\ No newline at end of file
daemon_reload: yes
- name: copy openhab-backup scripts
template:
src: openhab-backup.sh.j2
dest: "/usr/local/bin/openhab-backup.sh"
owner: root
group: root
mode: 0755
- name: Deploy openhab-backup timer
template:
src: openhab-backup.timer.j2
dest: "/etc/systemd/system/openhab-backup.timer"
owner: root
group: root
mode: 0644
notify:
- restart openhab-backup-timer
- name: Deploy openhab-backup service
template:
src: openhab-backup.service.j2
dest: "/etc/systemd/system/openhab-backup.service"
owner: root
group: root
mode: 0644
notify:
- restart openhab-backup-timer
- name: Enable and start timer
systemd:
name: "openhab-backup.timer"
daemon_reload: yes
enabled: yes
state: started
\ No newline at end of file
[Unit]
Description=Openhab Backup
[Service]
Type=simple
ExecStart=/usr/local/bin/openhab-backup.sh
StandardError=journal
\ No newline at end of file
#!/usr/bin/env bash
set -ueo pipefail
BACKUP_FILE=openhab-`date +%F`.zip
BACKUP_FULL_PATH=/var/lib/openhab/backups/${BACKUP_FILE}
# Do backup
/usr/share/openhab/runtime/bin/backup ${BACKUP_FULL_PATH}
{% if swift_upload %}
SEGMENT_SIZE=1073741824
export OS_AUTH_URL={{ OS_AUTH_URL }}
export OS_IDENTITY_API_VERSION={{ OS_IDENTITY_API_VERSION |default(3) }}
export OS_USER_DOMAIN_NAME={{ OS_USER_DOMAIN_NAME | default("Default") }}
export OS_PROJECT_DOMAIN_NAME={{ OS_PROJECT_DOMAIN_NAME | default("Default") }}
export OS_TENANT_ID={{ OS_TENANT_ID }}
export OS_TENANT_NAME={{ OS_TENANT_NAME}}
export OS_REGION_NAME={{ OS_REGION_NAME }}
export OS_USERNAME={{ OS_USERNAME }}
export OS_PASSWORD={{ OS_PASSWORD }}
swift upload {{ openhab_swift_container }} ${BACKUP_FULL_PATH} --object-name ${BACKUP_FILE} --segment-size ${SEGMENT_SIZE}
{% if swift_delete %}
rm -f ${BACKUP_FULL_PATH}
{% endif %}
unset OS_AUTH_URL
unset OS_IDENTITY_API_VERSION
unset OS_USER_DOMAIN_NAME
unset OS_PROJECT_DOMAIN_NAME
unset OS_TENANT_ID
unset OS_TENANT_NAME
unset OS_REGION_NAME
unset OS_USERNAME
unset OS_PASSWORD
{% endif %}
[Unit]
Description=Openhab backup
[Timer]
# Define a calendar event (see `man systemd.time`)
OnCalendar={{ openhab_timer | default("daily") }}
Persistent=true
[Install]
WantedBy=timers.target
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment