Skip to content
Extraits de code Groupes Projets
Valider 60f76531 rédigé par Théo - Le Filament's avatar Théo - Le Filament
Parcourir les fichiers

change: improve backups handling

parent 7401534b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
---
## Odoo configuration
## Odoo PostgreSQL version
odoo_db_version: '13'
## Odoo version
odoo_version: '16.0'
## Odoo websocket URI (websocket from 16.0 onwards, longpolling before)
websocket_uri: 'websocket'
odoo_setup_version: '16'
odoo_setup_conf:
16:
odoo_version: '16.0'
postgres_version: '15'
websocket_uri: 'websocket'
15:
odoo_version: '15.0'
postgres_version: '13'
websocket_uri: 'longpolling'
14:
odoo_version: '14.0'
postgres_version: '13'
websocket_uri: 'longpolling'
12:
odoo_version: '12.0'
postgres_version: '10'
websocket_uri: 'longpolling'
10:
odoo_version: '10.0'
postgres_version: '9.6'
websocket_uri: 'longpolling'
odoo_setup_version: 16
## Custom modules default URL for retrieving custom modules :
custom_modules_base_url: "https://sources.le-filament.com/lefilament"
......@@ -136,21 +107,23 @@ metabase: false
## OPTIONAL - For Backups only
# swift_accounts:
## Parameters for pushing backups to Object Storage - Instance 1
# swift_odoo_authurl: https://auth.cloud.ovh.net/v3/
# swift_odoo_authversion: 3
# swift_odoo_tenantid: "132e1fa"
# swift_odoo_tenantname: "12312534534"
# swift_odoo_username: "testuser"
# swift_odoo_password: "testpassword"
# swift_odoo_regionname: "GRA"
# - authurl: https://auth.cloud.ovh.net/v3/
# authversion: 3
# tenantid: "132e1fa"
# tenantname: "12312534534"
# username: "testuser"
# password: "testpassword"
# regionname: "GRA"
#
## Parameters for pushing backups to Object Storage - Instance 2
# swift_odoo2_authurl: https://auth.cloud.ovh.net/v3/
# swift_odoo2_authversion: 3
# swift_odoo2_tenantid: "12323534ab"
# swift_odoo2_tenantname: "123124235345"
# swift_odoo2_username: "testuser"
# swift_odoo2_password: "testpassword"
# swift_odoo2_regionname: "DE"
# - authurl: https://auth.cloud.ovh.net/v3/
# authversion: 3
# tenantid: "12323534ab"
# tenantname: "123124235345"
# username: "testuser"
# password: "testpassword"
# regionname: "DE"
## Passphrase for backups encryption
# odoo_backup_pass: notSecureEnoughPasswordToBeModified
......@@ -158,13 +158,14 @@
- name: Copy compose file to restore db from backup_instance
template:
src: restore-odootest.yaml.j2
dest: "/home/docker/backups/restore-{{ item.key }}{{ account.key }}.yaml"
dest: "/home/docker/backups/restore-{{ item.key }}{{ account_index + 1 }}.yaml"
owner: root
group: root
mode: '0400'
with_dict: "{{ swift_accounts }}"
loop: "{{ swift_accounts }}"
loop_control:
label: "{{ account.key }}"
label: "account {{ account_index + 1 }}"
index_var: account_index
loop_var: account
# --------------------------------------------------
......@@ -174,33 +175,31 @@
when: item.value.backup_instance | default(false) == item.key and item.value.backup_host | default(inventory_hostname) == inventory_hostname and inventory_hostname in groups.maintenance_contract
tags: 'backup_odoo'
block:
- name: Copy docker compose for backups
- name: "Copy docker compose for backup account {{ account_index + 1 }}"
template:
src: backup.yaml.j2
dest: "/home/docker/backups/backup-{{ item.key }}{{ account.key }}.yaml"
dest: "/home/docker/backups/backup-{{ item.key }}{{ account_index + 1 }}.yaml"
owner: root
group: root
mode: '0400'
with_dict: "{{ swift_accounts }}"
loop: "{{ swift_accounts }}"
loop_control:
label: "{{ account.key }}"
label: "account {{ account_index + 1 }}"
index_var: account_index
loop_var: account
# TODO: duplicate with swift_accounts
- name: Add cron job to run backup every day
- name: "Add cron job to run backup account {{ account_index + 1 }} every day"
cron:
name: "backup {{ item.key }}"
minute: "50"
hour: "01"
job: /usr/local/bin/docker-compose -f /home/docker/backups/backup-{{ item.key }}1.yaml run --rm backup_odoo
- name: Add cron job to run backup2 every day
cron:
name: "backup2 {{ item.key }}"
minute: "00"
hour: "23"
job: /usr/local/bin/docker-compose -f /home/docker/backups/backup-{{ item.key }}2.yaml run --rm backup_odoo
name: "backup {{ item.key }}{{ account_index + 1 }}"
minute: "{{ '%M' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + ( swift_accounts | length - (account_index + 1)) * ((backup_time_slot_duration | community.general.to_seconds - swift_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}"
hour: "{{ '%H' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + ( swift_accounts | length - (account_index + 1)) * ((backup_time_slot_duration | community.general.to_seconds - swift_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}"
job: "/usr/local/bin/docker-compose -f /home/docker/backups/backup-{{ item.key }}{{ account_index + 1 }}.yaml run --rm backup_odoo"
loop: "{{ swift_accounts }}"
loop_control:
label: "account {{ account_index + 1 }}"
index_var: account_index
loop_var: account
# Flush handlers.
- name: set facts
......
......@@ -9,19 +9,19 @@ services:
PGUSER: "{{ item.value.db_user }}"
PGPASSWORD: "{{ item.value.db_pass }}"
PASSPHRASE: "{{ item.value.odoo_backup_pass | default(item.value.master_pass) }}"
SWIFT_USERNAME: "{{ account.value.swift_username }}"
SWIFT_PASSWORD: "{{ account.value.swift_password }}"
SWIFT_AUTHURL: "{{ account.value.swift_authurl }}"
SWIFT_AUTHVERSION: {{ account.value.swift_authversion }}
SWIFT_TENANTNAME: "{{ account.value.swift_tenantname }}"
SWIFT_TENANTID: "{{ account.value.swift_tenantid }}"
SWIFT_REGIONNAME: "{{ account.value.swift_regionname }}"
SWIFT_USERNAME: "{{ account.username }}"
SWIFT_PASSWORD: "{{ account.password }}"
SWIFT_AUTHURL: "{{ account.authurl }}"
SWIFT_AUTHVERSION: {{ account.authversion }}
SWIFT_TENANTNAME: "{{ account.tenantname }}"
SWIFT_TENANTID: "{{ account.tenantid }}"
SWIFT_REGIONNAME: "{{ account.regionname }}"
JOB_200_WHEN: "never"
JOB_300_WHAT: "pg_dump --no-owner --format c --file $$SRC/$$PGDATABASE.pgdump && backup --full-if-older-than 6D"
JOB_302_WHAT: "dup remove-all-but-n-full 5 --force $$DST $$@"
JOB_302_WHEN: "daily"
volumes:
- {{ item.key }}{{ account.key }}_backup_cache:/root/.cache/duplicity/:z
- {{ item.key }}{{ account_index + 1 }}_backup_cache:/root/.cache/duplicity/:z
- {{ item.key }}_filestore:/mnt/backup/src/odoo:z
{% if item.value.metabase | default(false) %}
- {{ item.key }}_metabase:/mnt/backup/src/metabase:z
......@@ -40,7 +40,7 @@ networks:
encrypted: 1
volumes:
{{ item.key }}{{ account.key }}_backup_cache:
{{ item.key }}{{ account_index + 1 }}_backup_cache:
{{ item.key }}_filestore:
external: true
{% if item.value.metabase | default(false) %}
......
......@@ -7,19 +7,19 @@ services:
- {{ item.key }}_default
- public
volumes:
- backups_{{ item.value.backup_instance }}{{ account.key }}_backup_cache:/root/.cache/duplicity/:z
- backups_{{ item.value.backup_instance }}{{ account_index + 1 }}_backup_cache:/root/.cache/duplicity/:z
- {{ item.key }}_filestore:/mnt/backup/src/odoo:z
- ./post_restore-{{ item.key }}.sql:/tmp/post-restore.sql:ro
- ./pre_restore-{{ item.key }}.sql:/tmp/pre-restore.sql:ro
environment:
PGDATABASE: "{{ item.value.db }}"
SWIFT_USERNAME: "{{ account.value.swift_username }}"
SWIFT_PASSWORD: "{{ account.value.swift_password }}"
SWIFT_AUTHURL: "{{ account.value.swift_authurl }}"
SWIFT_AUTHVERSION: {{ account.value.swift_authversion }}
SWIFT_TENANTNAME: "{{ account.value.swift_tenantname }}"
SWIFT_TENANTID: "{{ account.value.swift_tenantid }}"
SWIFT_REGIONNAME: "{{ account.value.swift_regionname }}"
SWIFT_USERNAME: "{{ account.username }}"
SWIFT_PASSWORD: "{{ account.password }}"
SWIFT_AUTHURL: "{{ account.authurl }}"
SWIFT_AUTHVERSION: {{ account.authversion }}
SWIFT_TENANTNAME: "{{ account.tenantname }}"
SWIFT_TENANTID: "{{ account.tenantid }}"
SWIFT_REGIONNAME: "{{ account.regionname }}"
OPTIONS: "--force"
DST: "swift://{{ item.value.backup_instance }}_{{ item.value.backup_host | default(inventory_hostname) | lower }}"
PGUSER: "{{ odoo_instances[item.value.prod_instance | default(item.key )].db_user }}"
......@@ -35,7 +35,7 @@ networks:
encrypted: 1
volumes:
backups_{{ item.value.backup_instance }}{{ account.key }}_backup_cache:
backups_{{ item.value.backup_instance }}{{ account_index + 1 }}_backup_cache:
{% if item.value.backup_host | default(inventory_hostname) == inventory_hostname %}
external: true
{% endif %}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter