]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Completing (hpefully) dirsrv offline backup
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 15:06:03 +0000 (16:06 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 15:06:03 +0000 (16:06 +0100)
playbooks/offline-backup-ldap-server.yaml
roles/389ds-offline-backup/tasks/directories.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/directory.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/filesystem.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/filesystems.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/hashfile.yaml [new file with mode: 0644]
roles/389ds-offline-backup/tasks/main.yaml

index fec708cf8f516b624cef5c93a64f04236a5b6d5c..bb412a28f97e9a983ee967fff6448b479b10ea1d 100644 (file)
@@ -86,6 +86,8 @@
             name: 389ds-offline-backup
           vars:
             stop_instance: true
+            create_backup_directory: true
+            ds389_create_filesystem_backups: true
 
         - name: "Enabling  Wazuh service."
           ansible.builtin.service:
diff --git a/roles/389ds-offline-backup/tasks/directories.yaml b/roles/389ds-offline-backup/tasks/directories.yaml
new file mode 100644 (file)
index 0000000..cc7af07
--- /dev/null
@@ -0,0 +1,11 @@
+---
+
+# Ensuring backup directories
+
+- name: "Ensure existence of backup directories."
+  include_tasks: "directory.yaml"
+  loop: "{{ [backup_directory, ds389_backup_directory] }}"
+  loop_control:
+    loop_var: directory
+
+# vim: filetype=yaml
diff --git a/roles/389ds-offline-backup/tasks/directory.yaml b/roles/389ds-offline-backup/tasks/directory.yaml
new file mode 100644 (file)
index 0000000..383d297
--- /dev/null
@@ -0,0 +1,51 @@
+---
+
+- debug:
+    msg: "Ensuring backup directory {{ directory | quote }}."
+
+- name: "Get stat of directory."
+  ansible.builtin.stat:
+    path: "{{ directory }}"
+  register: stat_backup_directory
+
+- name: "File stat of directory."
+  debug:
+    var: stat_backup_directory
+    verbosity: 3
+
+- name: "Directory path exists."
+  when: stat_backup_directory.stat.exists == true
+  block:
+
+    - debug:
+        msg: "Path {{ directory | quote }} to backup directory already exists."
+        verbosity: 1
+
+    - name: "Check, whether path is a directory."
+      ansible.builtin.fail:
+        msg: "The path {{ directory | quote }} exists, but is not a directory."
+      when: stat_backup_directory.stat.isdir != true
+
+- name: "Directory path does not exists."
+  when: stat_backup_directory.stat.exists != true
+  block:
+
+    - name: "Backup directory does not exists"
+      ansible.builtin.fail:
+        msg: "Backup directory {{ directory | quote }} does not exists."
+      when: create_backup_directory != true and ansible_check_mode != true
+
+    - debug:
+        msg: "Backup directory {{ directory | quote }} still does not exists."
+
+    - name: "Creating backup directory."
+      ansible.builtin.file:
+        path: "{{ directory }}"
+        state: directory
+        recurse: yes
+        owner: root
+        group: root
+        mode: '0755'
+      when: create_backup_directory == true
+
+# vim: filetype=yaml
diff --git a/roles/389ds-offline-backup/tasks/filesystem.yaml b/roles/389ds-offline-backup/tasks/filesystem.yaml
new file mode 100644 (file)
index 0000000..78ec8d8
--- /dev/null
@@ -0,0 +1,18 @@
+---
+
+- name: "Defining target archive file."
+  ansible.builtin.set_fact:
+    archive_file: "{{ backup_directory }}/backup.{{ slapd_instance }}.{{ filesystem | regex_replace('^/*') | regex_replace('/+', '_') }}.{{ cur_timestamp }}.tar.bz2 }}"
+
+- debug:
+    msg: "Creating archive {{ archive_file }} from directory {{ filesystem | quote }}."
+
+- name: "Creating archive file."
+  community.general.archive:
+    path: "{{ filesystem }}"
+    dest: "{{ archive_file }}"
+    format: bz2
+    remove: false
+    force_archive: true
+
+# vim: filetype=yaml
diff --git a/roles/389ds-offline-backup/tasks/filesystems.yaml b/roles/389ds-offline-backup/tasks/filesystems.yaml
new file mode 100644 (file)
index 0000000..1f045bc
--- /dev/null
@@ -0,0 +1,17 @@
+---
+
+# Backing up complete important filesystems of 389ds directory servers
+
+- name: "Archiving a complete filesystem."
+  include_tasks: "filesystem.yaml"
+  loop: "{{ ds389_directories_to_backup }}"
+  loop_control:
+    loop_var: filesystem
+
+- name: "Create hash sum files from created archives."
+  include_tasks: "hashfile.yaml"
+  loop: "{{ ['md5', 'sha256', 'sha512'] }}"
+  loop_control:
+    loop_var: hash_type
+
+# vim: filetype=yaml
diff --git a/roles/389ds-offline-backup/tasks/hashfile.yaml b/roles/389ds-offline-backup/tasks/hashfile.yaml
new file mode 100644 (file)
index 0000000..8ebcad1
--- /dev/null
@@ -0,0 +1,26 @@
+---
+
+- name: "Defining hash sum file."
+  ansible.builtin.set_fact:
+    hash_file: "{{ backup_directory }}/backup-tars.{{ slapd_instance }}.{{ cur_timestamp }}.{{ hash_type }}"
+
+- debug:
+    msg: "Creating {{ hash_file | quote }} from files {{ backup_directory }}/backup.{{ slapd_instance }}.*.{{ cur_timestamp }}.tar.bz2 }}"
+
+- name: "Defining command for creating hash sum file."
+  ansible.builtin.set_fact:
+    hash_cmd: "{{ hash_type }}sum backup.{{ slapd_instance }}.*.{{ cur_timestamp }}.tar.bz2 > {{ hash_file | quote }}"
+
+- name: "Command for creating hash sum file."
+  debug:
+    var: hash_cmd
+    verbosity: 0
+
+- name: "Creating hash sum file."
+  ansible.builtin.shell:
+    chdir: "{{ backup_directory }}"
+    cmd: "{{ hash_cmd }}"
+    creates: "{{ hash_file }}"
+
+
+# vim: filetype=yaml
index 23efae30780002c4b3df3b345788112df26be149..e812f3fc036e00d08d9f15bbcc8554c06277aa36 100644 (file)
@@ -19,6 +19,9 @@
     var: get_slapd_status
     verbosity: 2
 
+- name: "Ensuring backup directories."
+  include_tasks: "directories.yaml"
+
 - name: "Getting running state of slapd instance."
   ansible.builtin.set_fact:
     slapd_is_running: false
   loop_control:
     loop_var: backend
 
+- name: "Archiving directories."
+  include_tasks: "filesystems.yaml"
+  when: ds389_create_filesystem_backups == true
+
 - name: "Start LDAP server instance, when it was stopped before."
   when: ds389_instance_was_stopped == true
   block: