]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Extending Ansible role 389ds-offline-backup
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 13:14:59 +0000 (14:14 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 13:14:59 +0000 (14:14 +0100)
inventory/dpx-ldap-dev1.yaml
inventory/dpx-ldap-prd.yaml
inventory/dpx-ldap-test.yaml
inventory/spk-ldap-live.yaml
inventory/spk-ldap-stage.yaml
roles/389ds-offline-backup/defaults/main.yaml
roles/389ds-offline-backup/tasks/backend.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/main.yaml

index 35d884bf836fff3063295df54efa6256c8e04e78..c8c5144c8f1c701d49f6454901367937f6ff4f09 100644 (file)
@@ -16,7 +16,8 @@ all:
           slapd_instance: dev-ds03
           ldap_uri: 'ldaps://dev-ds03.pixelpark.com'
       vars:
-        suffix: 'o=isp'
+        default_suffix: 'o=isp'
+        default_backend_name: 'userroot'
         dirsrv_root_dn: 'cn=admin'
         dirsrv_root_passwd_file: '/root/.private/dirsrv-mngr-pwd-wonl.txt'
         replication_manager_dn: 'cn=Replication Manager,cn=config'
index f87cff317072b78c10d99f17c67bc2cb75054a57..f6d4205ce71ec6f8bb5e96de586246a139600a12 100644 (file)
@@ -16,7 +16,8 @@ all:
           slapd_instance: prd-ds13
           ldap_uri: 'ldaps://prd-ds13.pixelpark.com'
       vars:
-        suffix: 'o=isp'
+        default_suffix: 'o=isp'
+        default_backend_name: 'userroot'
         dirsrv_root_dn: 'cn=admin'
         dirsrv_root_passwd_file: '/root/.private/dirsrv-mngr-pwd-wonl.txt'
         replication_manager_dn: 'cn=Replication Manager,cn=config'
index 23d81c794e0ec421779a45dc16380196305755a6..9adb63c168e40d0e8cd2827bf8493abba1d45ed8 100644 (file)
@@ -16,7 +16,8 @@ all:
           slapd_instance: test-ds03
           ldap_uri: 'ldaps://test-ds03.pixelpark.com'
       vars:
-        suffix: 'dc=pixelpark,dc=net'
+        default_suffix: 'dc=pixelpark,dc=net'
+        default_backend_name: 'userroot'
         dirsrv_root_dn: 'cn=admin'
         dirsrv_root_passwd_file: '/root/.private/dirsrv-mngr-pwd-wonl.txt'
         replication_manager_dn: 'cn=Replication Manager,cn=config'
index e79c716db3eec930b9275f502b63335023ff768e..34e284f89c3a16a3a7ecdf7af0d1f7ad21d10162 100644 (file)
@@ -17,7 +17,8 @@ all:
         live-ldap-hap02.spk.pixelpark.net: {}
   vars:
     ansible_user: root
-    suffix: 'dc=spk,dc=pixelpark,dc=net'
+    default_suffix: 'dc=spk,dc=pixelpark,dc=net'
+    default_backend_name: 'userroot'
     dirsrv_root_dn: 'cn=admin'
     dirsrv_root_passwd_file: '/root/.private/dirsrv-mngr-pwd-wonl.txt'
     replication_manager_dn: 'cn=Replication Manager,cn=config'
index 4be4adb1aadbb758c7ac3b5074eba76c52e21d1f..473552a3be6c859192c491ca8c89382243491aa8 100644 (file)
@@ -27,7 +27,8 @@ all:
         live-ldap-hap02.spk.pixelpark.net: {}
   vars:
     ansible_user: root
-    suffix: 'dc=spk,dc=pixelpark,dc=net'
+    default_suffix: 'dc=spk,dc=pixelpark,dc=net'
+    default_backend_name: 'userroot'
     dirsrv_root_dn: 'cn=admin'
     dirsrv_root_passwd_file: '/root/.private/dirsrv-mngr-pwd-wonl.txt'
     replication_manager_dn: 'cn=Replication Manager,cn=config'
index 26012b3c212245dce4022fa18f471ca569a134f3..4a785094ee75c12b2d25b8cfdcb16afb27df0977 100644 (file)
@@ -4,9 +4,12 @@ stop_instance: false
 ds389_instance_was_stopped: false
 
 backup_directory: '/var/backup'
+ds389_backup_directory: '/var/backup/dirsrv'
 create_backup_directory: false
 
-directories_to_backup:
+ds389_create_filesystem_backups: false
+
+ds389_directories_to_backup:
   - /etc/dirsrv
   - /root
   - /home
diff --git a/roles/389ds-offline-backup/tasks/backend.yaml b/roles/389ds-offline-backup/tasks/backend.yaml
new file mode 100644 (file)
index 0000000..a390d9b
--- /dev/null
@@ -0,0 +1,37 @@
+---
+# Creating offline backup of a particular LDAP server backend
+# -----------------------------------------------------------
+
+- debug:
+    msg: "Creating offline backup of 389ds directory server backend {{ backend_name | quote }} of instance {{ slapd_instance | quote }}."
+
+- name: "Define backup file."
+  ansible.builtin.set_fact:
+    backup_file: "{{ ds389_backup_directory }}/dump-offline-dirsrv.{{ slapd_instance }}.{{ backend_name }}.{{ cur_timestamp }}.ldif"
+
+- name: "Define command for offline backup."
+  ansible.builtin.set_fact:
+    cmd_offline_backup: "dsctl -v {{ full_slapd_instance | quote }} db2ldif --replication {{ backend_name | quote }} {{ backup_file | quote }}"
+
+- name: "The offline backup command:"
+  debug:
+    var: cmd_offline_backup
+    verbosity: 0
+
+- name: "Executing offline backup."
+  ansible.builtin.shell: "{{ cmd_offline_backup }}"
+  register: offline_backup_result
+
+- name: "Offline backup results:"
+  debug:
+    var: offline_backup_result.stdout
+    verbosity: 0
+
+- name: "Compressing the offline backup file."
+  community.general.archive:
+    path: "{{ backup_file }}"
+    dest: "{{ backup_file }}.bz2"
+    format: bz2
+    remove: true
+
+# vim: filetype=yaml
index 3f1433a4e4261534bddbfb7df1ca67db6f7ed888..23efae30780002c4b3df3b345788112df26be149 100644 (file)
     slapd_is_running: false
   when: ( get_slapd_status.stdout | regex_search('^Instance \".*\" is not running', ignorecase=True) ) is not empty
 
+- name: "Get backends and suffixes from the running instance."
+  when: slapd_is_running == true
+  block:
+
+    - name: "Retrieve all backends."
+      ansible.builtin.shell: "dsconf {{ slapd_instance | quote  }} backend suffix list"
+      register: get_backend_suffix_list
+      changed_when: false
+      check_mode: false
+
+    - name: "Show current get_backend_suffix_list"
+      debug:
+        var: get_backend_suffix_list
+        verbosity: 2
+
+    - name: "Set backend variable"
+      no_log: true
+      set_fact:
+        suffix_names: "{{ get_backend_suffix_list.stdout_lines | map('regex_replace', '\\s+\\(.+\\)\\s*$', '') | list }}"
+        backend_names: "{{ get_backend_suffix_list.stdout_lines | map('regex_replace', '^.*\\((.+)\\)\\s*$', '\\1') | list }}"
+
+    - name: "Set suffixes dict"
+      no_log: true
+      set_fact:
+        suffixes: "{{ dict( suffix_names | zip(backend_names) ) }}"
+
+    - name: "Show current suffixes"
+      debug:
+        var: suffixes
+        verbosity: 0
+
+- name: "Use default backend name and suffix, because instance is not running."
+  when: slapd_is_running != true
+  block:
+
+    - name: "Define suffixes from defaults because instance is not running."
+      ansible.builtin.set_fact:
+        suffixes: "{{ [[default_suffix, default_backend_name]] | community.general.dict }}"
+
+    - name: "Show default suffixes"
+      debug:
+        var: suffixes
+        verbosity: 0
+
 - name: "Stopping instance, if running"
   when: stop_instance == true and slapd_is_running == true
   block:
         msg: "Cannot perform offline backup, LDAP server instance {{ slapd_instance | quote }} is still running."
       when: ansible_check_mode == false
 
+- name: "Perform the offline backup."
+  include_tasks: 'backend.yaml'
+  vars:
+    backend_name: "{{ backend.name }}"
+    suffix: "{{ backend.suffix }}"
+  loop: "{{ suffixes | dict2items(key_name='suffix', value_name='name') }}"
+  loop_control:
+    loop_var: backend
+
 - name: "Start LDAP server instance, when it was stopped before."
   when: ds389_instance_was_stopped == true
   block: