-
Notifications
You must be signed in to change notification settings - Fork 3
Add Database Backup Feature (Disabled by Default) and Use backup User for Multi-DB Support #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,36 @@ | ||
| --- | ||
| # Yamllint configuration should be compatible with Ansible, | ||
| # see https://ansible.readthedocs.io/projects/lint/rules/yaml/#yamllint-configuration | ||
|
|
||
| extends: default | ||
|
|
||
| rules: | ||
| line-length: disable | ||
| comments: | ||
| # https://github.com/prettier/prettier/issues/6780 | ||
| min-spaces-from-content: 1 | ||
| # https://github.com/adrienverge/yamllint/issues/384 | ||
| comments-indentation: false | ||
| document-start: disable | ||
| # 160 chars was the default used by old E204 rule, but | ||
| # you can easily change it or disable in your .yamllint file. | ||
| line-length: | ||
| max: 200 | ||
| # We are adding an extra space inside braces as that's how prettier does it | ||
| # and we are trying not to fight other linters. | ||
| braces: | ||
| min-spaces-inside: 0 # yamllint defaults to 0 | ||
| max-spaces-inside: 1 # yamllint defaults to 0 | ||
| # key-duplicates: | ||
| # forbid-duplicated-merge-keys: true # not enabled by default | ||
| octal-values: | ||
| forbid-implicit-octal: true # yamllint defaults to false | ||
| forbid-explicit-octal: true # yamllint defaults to false | ||
| # quoted-strings: | ||
| # quote-type: double | ||
| # required: only-when-needed | ||
|
|
||
|
|
||
| ignore: | | ||
| venv/ | ||
| .roles/ | ||
| .cache/ | ||
| .github/ | ||
| venv/ |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,3 +10,14 @@ database_root_user: root | |||||||||
| opencast_mariadb_max_connections: 512 | ||||||||||
| # set buffer pool size to ~80% of total memory if db runs on its own host | ||||||||||
| opencast_mariadb_innodb_buffer_pool_size: "{{ ((ansible_memtotal_mb / 1024) * 0.8) | int }}G" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| # === Database backup feature (enabled) === | ||||||||||
| database_backup_enabled: false | ||||||||||
| database_backup_output_path: None | ||||||||||
| database_backup_schedule: "*-*-* 05:00:00" # Systemd OnCalendar format | ||||||||||
| database_backup_keep: 7 | ||||||||||
| database_backup_dbs: [] # list of databases | ||||||||||
|
||||||||||
| database_backup_dbs: [] # list of databases | |
| # list of databases | |
| database_backup_dbs: | |
| - "{{ database_name }}" |
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| - name: Fail if backup enabled but no output path given | ||
| ansible.builtin.fail: | ||
| msg: "database_backup_output_path must be set when database_backup_enabled = true" | ||
| when: | ||
| - database_backup_enabled | ||
| - database_backup_output_path | length == 0 | ||
|
|
||
| - name: Ensure backup OS user exists | ||
| ansible.builtin.user: | ||
| name: "{{ database_backup_owner }}" | ||
| state: present | ||
| shell: /usr/sbin/nologin | ||
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| system: true | ||
NUZAT-TABASSUM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Ensure MariaDB backup user exists for each database | ||
| community.mysql.mysql_user: | ||
| name: "{{ database_backup_user }}" | ||
| password: "{{ database_backup_user_password }}" | ||
| host: "localhost" | ||
| priv: "{{ item }}.*:SELECT,LOCK TABLES,SHOW VIEW,EVENT,TRIGGER" | ||
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| state: present | ||
| login_user: "{{ database_root_user }}" | ||
| login_password: "{{ database_root_password }}" | ||
| loop: "{{ database_backup_dbs }}" | ||
| when: database_backup_enabled | ||
| no_log: true | ||
|
|
||
| - name: Ensure backup output directory exists | ||
| ansible.builtin.file: | ||
| path: "{{ database_backup_output_path }}" | ||
| state: directory | ||
| owner: "{{ database_backup_owner }}" | ||
| group: "{{ database_backup_group }}" | ||
| mode: "0750" | ||
| when: database_backup_enabled | ||
|
|
||
| - name: Install backup script | ||
| ansible.builtin.template: | ||
| src: database-backup.sh.j2 | ||
| dest: "{{ database_backup_output_path }}/database-backup.sh" | ||
| owner: "{{ database_backup_owner }}" | ||
| group: "{{ database_backup_group }}" | ||
| mode: "0750" | ||
| when: database_backup_enabled | ||
|
|
||
| - name: Install systemd service unit | ||
| ansible.builtin.template: | ||
| src: database-backup.service.j2 | ||
| dest: /etc/systemd/system/database-backup.service | ||
| mode: "0644" | ||
| when: database_backup_enabled | ||
|
|
||
| - name: Install systemd timer unit | ||
| ansible.builtin.template: | ||
| src: database-backup.timer.j2 | ||
| dest: /etc/systemd/system/database-backup.timer | ||
| mode: "0644" | ||
| when: database_backup_enabled | ||
|
|
||
| - name: Reload systemd daemon (if timers changed) | ||
| ansible.builtin.systemd: | ||
| daemon_reload: true | ||
| when: database_backup_enabled | ||
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Ensure backup timer is enabled and running | ||
| ansible.builtin.systemd: | ||
| name: database-backup.timer | ||
| enabled: true | ||
| state: started | ||
| when: database_backup_enabled | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [Unit] | ||
| Description=Opencast Database Backup | ||
| After=network.target | ||
| After=local-fs.target | ||
| After=remote-fs.target | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| User={{ database_backup_owner }} | ||
| Group={{ database_backup_group }} | ||
| ExecStart={{ database_backup_output_path }}/database-backup.sh | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| #!/usr/bin/env bash | ||||||
|
|
||||||
| DBUSER="{{ database_backup_user }}" | ||||||
| DBPASS="{{ database_backup_user_password }}" | ||||||
| OUTDIR="{{ database_backup_output_path }}" | ||||||
| KEEP={{ database_backup_keep }} | ||||||
| DBS=({% for db in database_backup_dbs %}{{ db }} {% endfor %}) | ||||||
|
||||||
| DBS=({% for db in database_backup_dbs %}{{ db }} {% endfor %}) | |
| DBS=({ database_backup_dbs | join(' ') }) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally fine using unicode characters, replacing it with asci will avoid issues in some circumstances. It's up to you to accept this suggestion or not.
But please use .sql.gz file extension.
| echo "Backing up $DB → $OUTDIR/db-backup-${DB}-${TS}.dump.gz" | |
| echo "Backing up $DB database to $OUTDIR/db-backup-${DB}-${TS}.sql.gz" |
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
NUZAT-TABASSUM marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [Unit] | ||
| Description=Run database backup daily | ||
|
|
||
| [Timer] | ||
| OnCalendar={{ database_backup_schedule }} | ||
| Persistent=true | ||
|
|
||
| [Install] | ||
| WantedBy=timers.target |
Uh oh!
There was an error while loading. Please reload this page.