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'
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'
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'
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'
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'
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
--- /dev/null
+---
+# 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
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: