Allow definition of custom handlers
diff --git a/backupninja/client.sls b/backupninja/client.sls
index 8ae8711..ddff4fe 100644
--- a/backupninja/client.sls
+++ b/backupninja/client.sls
@@ -1,4 +1,4 @@
-{%- from "backupninja/map.jinja" import client with context %}
+{%- from "backupninja/map.jinja" import client, service_grains with context %}
{%- if client.enabled %}
{%- if pillar.postgresql is defined or pillar.mysql is defined %}
@@ -53,6 +53,27 @@
{%- endif %}
+{%- for backup_name, backup in service_grains.backupninja.backup.iteritems() %}
+{%- set backup_index = loop.index %}
+{%- for action in backup.get('actions', []) %}
+
+backupninja_{{ backup_name }}_action_{{ loop.index }}:
+ file.managed:
+ - name: /etc/backup.d/0{{ backup_index }}.{{ backup_name }}_{{ loop.index }}.{{ backup.get('handler', 'sh') }}
+ - source: salt://backupninja/files/handler/{{ backup.get('handler', 'sh') }}.conf
+ - template: jinja
+ - mode: 600
+ - require_in:
+ - file: backupninja_remote_handler
+ - require:
+ - pkg: backupninja_packages
+ - defaults:
+ backup: {{ backup }}
+ action: {{ action }}
+
+{%- endfor %}
+{%- endfor %}
+
backupninja_client_grains_dir:
file.directory:
- name: /etc/salt/grains.d
diff --git a/backupninja/files/handler/sh.conf b/backupninja/files/handler/sh.conf
index 75b0162..9efdd4a 100644
--- a/backupninja/files/handler/sh.conf
+++ b/backupninja/files/handler/sh.conf
@@ -1,4 +1,5 @@
-# Note: the spaces around the equal sign ('=') are optional.
-when = saturdays at 05:30
+{%- if action.when is defined -%}
+when = {{ action.when }}
+{%- endif %}
-dpkg --get-selections > /var/backups/dpkg-selections.txt
+{{ action.cmd }}