Add offline backup for foremanctl#507
Conversation
15ba9dd to
c6de1eb
Compare
ianballou
left a comment
There was a problem hiding this comment.
I did an automated test run, take these with a grain of salt, but I wanted to post early in case they're real for extra time to test and fix.
Firstly, the DBs did get backed up, so awesome, but there were some hiccups that stopped the full process from running:
Bug #1: podman_network.yaml fails when no custom networks exist
File: src/playbooks/backup/tasks/podman_network.yaml
Severity: Blocker — prevents backup from completing
Description: The shell command podman network ls --format '{{.Name}}' | grep -v '^podman$' | while read net; do ... returns exit code 1 when there are no custom networks, because grep -v finds no matching lines.
Fix: Add || true after the grep, or use a different approach:
# Option A: tolerate empty result
failed_when: networks_json.rc not in [0, 1]
# Option B: check first, skip if no custom networksBug #2: Wrong Foreman tasks API endpoint
File: src/playbooks/backup/tasks/preflight.yaml
Severity: High — preflight silently skips running task detection
Description: Uses https://{{ fqdn }}/api/v2/tasks?state=running which returns 404. The correct endpoint is https://{{ fqdn }}/foreman_tasks/api/tasks?state=running&search=state%3Drunning. Because failed_when: false is set, the error is silently ignored.
Impact: Backups will proceed even with running Foreman tasks, risking data inconsistency.
Bug #3: pg_isready and pg_dump not available on host
... I cut the output here, I'm not sure why these commands weren't on my box. It's not related to this PR I don't think.
Bug #4: Hardcoded parameters.yaml path in metadata task
File: src/playbooks/backup/tasks/metadata.yaml
Severity: Low — affects metadata accuracy only
Description: ansible.builtin.slurp reads from /var/lib/foremanctl/parameters.yaml but foremanctl's state directory is configurable via OBSAH_STATE. In dev/vagrant setups, the actual path is different (e.g., /vagrant/.var/lib/foremanctl/parameters.yaml).
Impact: enabled_features: [] in metadata despite features being configured. Doesn't affect DB dump correctness.
Fix: Use the state_dir variable instead of hardcoding the path.
|
Will update the tasks endpoint and parameters.yaml path.. About the podman networks, those are created for IOP.. Like https://github.com/theforeman/foremanctl/blob/master/src/roles/iop_network/tasks/main.yaml so I'd assume we have that present in production deployments. We can add some handling for when it's not. |
|
Maybe nitpick but does it make sense to include the not yet implemented flags when doing |
I am fine either way but it's helpful guidance for future PRs and documentation to look at. |
4da7174 to
10c3e00
Compare
|
not a full review (I stopped somewhere around the secrets backup), but overall this feels a lot like "let's write a huge bash script and then wrap it in YAML" and not like Ansible :( |
b066ac9 to
16293d2
Compare
a67e4d0 to
273fa50
Compare
|
@ehelms @evgeni @ianballou Does this 🍞 look baked enough? We have some follow up PRs in this area we are starting to focus on based on this PR if we think this looks good. |
e82328e to
40a2bd1
Compare
0e59f8e to
78230ae
Compare
ianballou
left a comment
There was a problem hiding this comment.
A few small comments, overall this is working well. Overview of my testing:
- All three databases dumped and valid
- State directory archived (passwords, OAuth keys, parameters.yaml, and certs when `OBSAH_STATE=/var/lib/foremanctl`)
- Pulp content + encryption keys captured
- `--skip-pulp-content` works
- Preflight checks (tasks, amcheck) work
- Services always come back up after backup or failure
- No dead code
- Restore works (with some bugs caused by the restore code, not backup)
The comments are minor and non-blocking from my standpoint, so I'm going to ack this. If we discover anything else during restore (which I don't expect since I tested restore), I think we can address it there.
| - "../../vars/flavors/{{ flavor }}.yml" | ||
| - "../../vars/{{ certificates_source }}_certificates.yml" | ||
| - "../../vars/foreman.yml" | ||
| - "../../vars/database.yml" |
There was a problem hiding this comment.
This use of database.yml causes password files to be created even for databases that don't exist. In my case, it was for the IoP databases on my vanilla Katello installation.
I'm not sure this should be fixed by backup/restore. Without being an Ansible expert, I wonder if backup/restore should not be responsible for filtering out databases that are outside of the scope of features used in the installation. Otherwise we'll have having feature filtering logic spread all over.
This is not a critical issue I don't think. Side effect is that my machine ended up with:
-rw------- 1 root root 21 Jun 16 14:46 iop-advisor-db-password
-rw------- 1 root root 21 Jun 16 14:46 iop-inventory-db-password
-rw------- 1 root root 21 Jun 16 14:46 iop-remediation-db-password
-rw------- 1 root root 21 Jun 16 14:46 iop-vmaas-db-password
-rw------- 1 root root 21 Jun 16 14:46 iop-vulnerability-db-password
even though I had no IoP DBs. @ehelms do you think this is worth a broader issue?
There was a problem hiding this comment.
Yes - please file a github issue.
0ee6604 to
45db441
Compare
| hostname: "{{ ansible_fqdn }}" | ||
| os_version: "{{ ansible_distribution }} {{ ansible_distribution_version }}" | ||
| foremanctl_version: "{{ ansible_facts.packages['foremanctl'][0].version | default('unknown') if 'foremanctl' in ansible_facts.packages else 'unknown' }}" | ||
| online: false |
There was a problem hiding this comment.
I think this should be type: offline
There was a problem hiding this comment.
Updated to type: offline ✅
| incremental: false | ||
| timestamp: "{{ backup_timestamp }}" | ||
| databases: "{{ backup_databases_to_backup }}" | ||
| iop_enabled: "{{ 'iop' in enabled_features }}" |
There was a problem hiding this comment.
iop will be in the features list and is not needed here
ehelms
left a comment
There was a problem hiding this comment.
Two minor nitpicks. I am ok with adding tests as a follow up PR.
Implements comprehensive offline backup functionality for Foreman deployments: - Backs up all databases (foreman, candlepin, pulp, 5 IOP DBs) - Backs up podman secrets, networks, volumes, quadlet files - Backs up systemd units and foremanctl state - Includes metadata with container image digests for restore compatibility - Preflight checks for running tasks and database integrity (amcheck) - Automatic service restoration on failure Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
45db441 to
f027813
Compare
Why are you introducing these changes? (Problem description, related links)
This implements offline backup with foremanctl.
What are the changes introduced in this pull request?
Offline backup
foremanctl backupcommand for offline backups--skip-pulp-content)--wait-for-tasksoption)docs/user/backup.mdbackup,check_database_indexHow to test this pull request
I got a foremanctl box with normal deploy. On this box, clone foremanctl repo and checkout this branch.
cd /root/foremanctl
source .venv/bin/activate
export OBSAH_STATE=/var/lib/foremanctl
Then try ./foremanctl --help
Also,
You can run :
Command:
Steps to reproduce:
Checklist