Skip to content

Commit 45f58c5

Browse files
Merge branch 'main' into fix-rhosp-ocp-16-install
2 parents 359f544 + a01737b commit 45f58c5

File tree

6 files changed

+261
-1
lines changed

6 files changed

+261
-1
lines changed

dolibarr/k8s/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ PostgreSQL
8787
ansible-playbook pgsql/k8s/helm/ansible/pgsql-uninstall-playbook.yaml \
8888
-e @dolibarr/k8s/helm/ansible/defaults/main.yaml
8989
----
90+
91+
== Backup and Restore
92+
93+
Check the link:backupNRestore.adoc[Dolibarr Backup and Restore] document.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
- name: "Dolibarr backup"
3+
hosts: "localhost"
4+
gather_facts: yes
5+
6+
pre_tasks:
7+
- name: "Fetch BACKUP_ROOT_FOLDER variable"
8+
ansible.builtin.set_fact:
9+
backup_root_folder: "{{ lookup('ansible.builtin.env', 'BACKUP_ROOT_FOLDER') }}"
10+
when: backup_root_folder is undefined
11+
12+
- name: "Check variables"
13+
ansible.builtin.assert:
14+
that:
15+
- "app_namespace is defined"
16+
- "backup_root_folder is defined and backup_root_folder | length > 0"
17+
18+
- name: "Set variables"
19+
ansible.builtin.set_fact:
20+
backup_file_prefix: "{{ ansible_date_time.iso8601_basic_short }}.dolibarr.backup"
21+
db_bk_user: "{{ db_user | default('root') }}"
22+
23+
- name: "Print pod card list"
24+
ansible.builtin.debug:
25+
var: backup_file_prefix
26+
27+
- name: "Collect backup folder stats"
28+
ansible.builtin.stat:
29+
path: "{{ backup_root_folder }}/{{ app_namespace }}"
30+
register: backup_folder_stats
31+
32+
- name: "Check backup folder exists"
33+
ansible.builtin.assert:
34+
that:
35+
- "backup_folder_stats.stat.exists"
36+
fail_msg:
37+
- "Folder {{ backup_root_folder }}/{{ app_namespace }} must exist."
38+
39+
tasks:
40+
- name: "Get PostgreSQL pod"
41+
kubernetes.core.k8s_info:
42+
kind: "Pod"
43+
namespace: "{{ app_namespace }}"
44+
validate_certs: false
45+
label_selectors:
46+
- app.kubernetes.io/name = postgresql
47+
register: postgresql_pod_list
48+
49+
- name: "Get Dolibarr Pod"
50+
kubernetes.core.k8s_info:
51+
kind: "Pod"
52+
namespace: "{{ app_namespace }}"
53+
validate_certs: false
54+
label_selectors:
55+
- app.kubernetes.io/name = dolibarr
56+
register: dolibarr_pod_list
57+
58+
- name: "Print pod list"
59+
ansible.builtin.debug:
60+
msg:
61+
- "postgresql_pod_list: {{ postgresql_pod_list.resources }}"
62+
- "postgresql_pod_list: {{ postgresql_pod_list.resources[0].metadata.name }}"
63+
- "postgresql_pod_list: {{ postgresql_pod_list.resources }}"
64+
- "postgresql_pod_list: {{ postgresql_pod_list.resources[0].metadata.name }}"
65+
verbosity: 2
66+
67+
- name: "Set Pod names"
68+
ansible.builtin.set_fact:
69+
postgresql_pod_name: "{{ postgresql_pod_list.resources[0].metadata.name }}"
70+
dolibarr_pod_name: "{{ dolibarr_pod_list.resources[0].metadata.name }}"
71+
72+
- name: "Print pod names"
73+
ansible.builtin.debug:
74+
msg:
75+
- "postgresql_pod_name: {{ postgresql_pod_name }}"
76+
- "dolibarr_pod_name: {{ dolibarr_pod_name }}"
77+
78+
- name: "Get ConfigMap"
79+
kubernetes.core.k8s_info:
80+
api_version: v1
81+
kind: ConfigMap
82+
name: postgresql
83+
namespace: "{{ app_namespace }}"
84+
register: postgresql_cm_info
85+
86+
- name: "Print CM list"
87+
ansible.builtin.debug:
88+
var: postgresql_cm_info.resources[0]
89+
verbosity: 2
90+
91+
- name: "Get Secrets"
92+
kubernetes.core.k8s_info:
93+
api_version: v1
94+
kind: Secret
95+
name: postgresql
96+
namespace: "{{ app_namespace }}"
97+
register: postgresql_secret_info
98+
99+
- name: "Extract DB password"
100+
ansible.builtin.set_fact:
101+
postgresql_user_pw: "{{ postgresql_secret_info.resources[0].data.POSTGRES_PASSWORD | b64decode }}"
102+
103+
- name: "Generate tar for Documents folder"
104+
kubernetes.core.k8s_exec:
105+
command: "tar --warning=no-file-changed -czvf /tmp/{{ backup_file_prefix }}.document.tgz /var/www/html/custom"
106+
namespace: "{{ app_namespace }}"
107+
pod: "{{ dolibarr_pod_name }}"
108+
register: dolibarr_file_bk_res
109+
failed_when: false
110+
111+
- name: "Print test result"
112+
ansible.builtin.debug:
113+
var: file_backup_test_res
114+
115+
116+
# # kubectl -n glpi cp ${GLPI_POD}:/tmp/${GLPI_MYSQL_DUMP_FILENAME_PREFIX}.files.tgz ${BACKUP_ROOT_FOLDER}/glpi/${GLPI_MYSQL_DUMP_FILENAME_PREFIX}.files.tgz
117+
- name: "Download document backup"
118+
kubernetes.core.k8s_cp:
119+
namespace: "{{ app_namespace }}"
120+
pod: "{{ dolibarr_pod_name }}"
121+
state: from_pod
122+
remote_path: "/tmp/{{ backup_file_prefix }}.document.tgz"
123+
local_path: "{{ backup_root_folder }}/{{ app_namespace }}/{{ backup_file_prefix }}.document.tgz"
124+
125+
- name: "Test file backup"
126+
ansible.builtin.shell: |
127+
tar -tzvf {{ backup_root_folder }}/{{ app_namespace }}/{{ backup_file_prefix }}.document.tgz
128+
register: file_backup_test_res
129+
130+
- name: "Download configuration file "
131+
kubernetes.core.k8s_cp:
132+
namespace: "{{ app_namespace }}"
133+
pod: "{{ dolibarr_pod_name }}"
134+
state: from_pod
135+
remote_path: "/var/www/html/conf/conf.php"
136+
local_path: "{{ backup_root_folder }}/{{ app_namespace }}/{{ backup_file_prefix }}.conf.php"
137+
138+
- name: "Change config.php file permissions"
139+
ansible.builtin.file:
140+
path: "{{ backup_root_folder }}/{{ app_namespace }}/{{ backup_file_prefix }}.conf.php"
141+
mode: '0600'
142+
143+
- name: Backup PostgreSQL database
144+
ansible.builtin.import_playbook: ../../../pgsql/k8s/kubectl/ansible/pgsql-backup-playbook.yaml
145+
vars:
146+
backup_file_prefix: "{{ backup_file_prefix }}"
147+
db_pod_name: "{{ postgresql_pod_name }}"
148+
k8s_ns: "{{ app_namespace }}"
149+
db_name: "{{ postgresql_cm_info.resources[0].data.POSTGRES_DB }}"
150+
db_user: "{{ postgresql_cm_info.resources[0].data.POSTGRES_USER }}"
151+
db_password: "{{ postgresql_user_pw }}"
152+
...

dolibarr/k8s/backupNrestore.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
= Dolibarr Backup and Restore
2+
:author: Antonio C.
3+
:email: <ac (at) trikorasolutions (dot) com>
4+
:revdate: {docdate}
5+
:toc: left
6+
:toc-title: Table of Contents
7+
:icons: font
8+
:description: GLPI backup and restore
9+
ifdef::env-github[]
10+
:tip-caption: :bulb:
11+
:note-caption: :information_source:
12+
:important-caption: :heavy_exclamation_mark:
13+
:caution-caption: :fire:
14+
:warning-caption: :warning:
15+
endif::[]
16+
17+
== Preparation
18+
19+
Define backup environment variables.
20+
21+
Set the root location of the backup folder.
22+
23+
[source,bash]
24+
----
25+
export BACKUP_ROOT_FOLDER=/z/_backup/apps
26+
----
27+
28+
Set the kube config file.
29+
30+
[source,bash]
31+
----
32+
export KUBECONFIG=~/.kube/config
33+
----
34+
35+
== Backup
36+
37+
=== With Ansible
38+
39+
[source,bash]
40+
----
41+
ansible-playbook dolibarr/k8s/ansible/dolibarr-backup-playbook.yaml \
42+
-e @dolibarr/k8s/ansible/defaults/main.yaml
43+
----
44+
45+
=== References
46+
47+
References:
48+
49+
* https://wiki.dolibarr.org/index.php/Backups
50+
51+
== Restore
52+
53+
For now, check the docs at https://wiki.dolibarr.org/index.php/Restores.

odoo/ansible/odoo-backup-playbook.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
- name: "Backup the database"
5151
ansible.builtin.shell: |
5252
curl -X POST -F 'master_pwd={{ odoo_master_pw }}' -F 'name={{ odoo_db_name }}' -F 'backup_format=zip' -o {{ backup_folder }}/{{ odoo_file_name }} {{ odoo_web_protocol | default('http') }}://{{ odoo_web_host }}:{{ odoo_web_port | default('8069')}}/web/database/backup
53+
register: backup_res
54+
55+
- name: "Print backup result"
56+
ansible.builtin.debug:
57+
var: backup_res
5358

5459
- name: "Test the backup file"
5560
ansible.builtin.shell: |

odoo/k8s/README.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ Installation
5353
[source,bash]
5454
----
5555
ansible-playbook odoo/ansible/odoo-backup-playbook.yaml \
56-
-e "@odoo/k8s/ansible/defaults/main.yaml" \
5756
-e "@odoo/k8s/ansible/defaults/odoo-${ODOO_VERSION}.yaml" \
57+
-e "@odoo/k8s/ansible/defaults/main.yaml" \
58+
-e odoo_db_name=${ODOO_DB} \
5859
-e odoo_master_pw=${ODOO_MASTER_PW} \
5960
-e backup_folder=${BACKUP_ROOT_FOLDER}/odoo
6061
----
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
- name: "Backup PostgreSQL database"
3+
hosts: "{{ k8s_host | default('localhost') }}"
4+
gather_facts: "{{ gathering_host_info | default('true') | bool == true }}"
5+
6+
pre_tasks:
7+
- name: "Check variables"
8+
ansible.builtin.assert:
9+
that:
10+
- "k8s_ns is defined and k8s_ns | length > 0"
11+
- "backup_root_folder is defined and backup_root_folder | length > 0"
12+
- "db_pod_name is defined and db_pod_name | length > 0"
13+
- "db_name is defined and db_name | length > 0"
14+
- "db_user is defined and db_user | length > 0"
15+
- "db_password is defined and db_password | length > 0"
16+
- "backup_file_prefix is defined and backup_file_prefix | length > 0"
17+
18+
tasks:
19+
20+
- name: "Print backup result"
21+
ansible.builtin.set_fact:
22+
# postgresql_bk_command: "pg_dump --username={{ db_user }} --dbname={{ db_name }} > /tmp/{{ backup_file_prefix }}.{{ k8s_ns }}.{{ db_pod_name }}.backup.sql"
23+
postgresql_bk_command: "pg_dump --username={{ db_user }} --dbname={{ db_name }}"
24+
25+
- name: "Print Backup command"
26+
ansible.builtin.debug:
27+
var: postgresql_bk_command
28+
29+
- name: "Backup PostgreSQL database"
30+
kubernetes.core.k8s_exec:
31+
command: "{{ postgresql_bk_command }}"
32+
namespace: "{{ k8s_ns }}"
33+
pod: "{{ db_pod_name }}"
34+
register: postgresql_dump_res
35+
36+
# - name: "Print backup result"
37+
# ansible.builtin.debug:
38+
# var: postgresql_dump_res
39+
40+
- name: "Download the DB backup to the backup folder - {{ k8s_ns }}"
41+
ansible.builtin.copy:
42+
content: "{{ postgresql_dump_res.stdout }}"
43+
# src: "{{ backup_file_prefix }}.{{ k8s_ns }}.{{ db_pod_name }}.backup.sql"
44+
dest: "{{ backup_root_folder }}/{{ k8s_ns }}/{{ backup_file_prefix }}.sql"
45+
...

0 commit comments

Comments
 (0)