Mattermost Backups, Upgrade Gate, Drill and Rollback¶
Mattermost's database migrations run one way. A new Mattermost version is applied only after the running version has a backup that was restored and started, and a failed upgrade is rolled back by restoring that backup (Renovate architecture §11). This is the Gitea pattern with a CloudNativePG database: the backup is an on-demand CNPG Backup to the backup store, and the restored copies are throwaway CNPG Clusters in the scratch namespace cnpg-drill (CloudNativePG).
The files on the volume mattermost-data (File storage) are backed up with the database, and every day on their own. The gate archives them while Mattermost is stopped and uploads the archive to <cluster>/mattermost/preupgrade/<created>-<version>-to-<target>/ in the backup store (files.tar in 1 GiB parts, each sent with Content-MD5 as the store's object lock requires, then files.env), as the Gitea and Harbor gates do. All file steps are in scripts/files.sh and scripts/s3.sh. The pods that run them are labelled app.kubernetes.io/name: mattermost-backup and run as uid and gid 2000, Mattermost's user.
| Part | Where | Flux Kustomization |
|---|---|---|
Gate mattermost/mattermost-preupgrade (Job), daily file backup mattermost/mattermost-files-backup (CronJob), weekly drill cnpg-drill/mattermost-restore-drill (CronJob), scripts and RBAC |
components/mattermost/backup/ |
mattermost-preupgrade |
Smoke check mattermost/mattermost-smoke (Job), rollback mattermost/mattermost-rollback (suspended Job) |
components/mattermost/rollback/ |
mattermost-postupgrade |
Both Kustomizations are in cluster/hetzner-mgmt/mattermost/kustomization.yaml. mattermost-preupgrade dependsOn mattermost-secrets (the namespace) and cnpg-drill (the scratch namespace and its backup-store ObjectStore). It substitutes cluster-config, because the files' prefixes in the backup store start with ${cluster_name} (the gate's and the drill's CLUSTER, the daily backup's PREFIX).
Versions¶
mattermostApp.image.tag in components/mattermost/base/helmrelease.yaml pins the Mattermost version; the chart's default would change it with every chart update. TARGET_VERSION in components/mattermost/backup/job.yaml and in components/mattermost/rollback/job.yaml must equal it. All three carry # renovate: datasource=docker depName=mattermost/mattermost-enterprise-edition, and the preset's mattermost group (/mattermost/) bumps them and the chart in one pull request. A chart-only update does not recreate the Jobs. It has no data migration, and Helm's rollback covers it.
The PostgreSQL image of mattermost-db (imageName in components/mattermost/base/postgres-cluster.yaml) has its own gate, mattermost-db-image-preupgrade, which backs up the database with Mattermost running (CloudNativePG: image gates). Never merge a Mattermost version and a PostgreSQL image change in one push.
The upgrade gate¶
The mattermost Kustomization dependsOn mattermost-preupgrade, whose health check is the Job mattermost/mattermost-preupgrade. The Job carries TARGET_VERSION and kustomize.toolkit.fluxcd.io/force: Enabled: a new version changes the pod template, so Flux recreates the Job, and mattermost is applied only once it has completed.
Any other change to the Job's pod template recreates it as well, against the unchanged TARGET_VERSION, such as a Renovate digest bump of its alpine/k8s image. Nothing upgrades then, so the gate passes without a backup when Mattermost already runs TARGET_VERSION (step 2 below): Mattermost stays up, and mattermost-backup-latest keeps naming the backup taken before the last upgrade (owner's decision #3616, 2026-11-26). Until then such a change ran a full gate with a few minutes of downtime, as the alpine/k8s digest bump of 2026-11-17 did. The drill CronJob runs the same alpine/k8s image, and Renovate bumps them in the same pull request, so the next weekly drill is the first run of the new image; the next Mattermost upgrade is the first gate to run it. A change to scripts/ or templates/ alone does not recreate the Job: the mattermost-backup-scripts ConfigMap keeps a stable name (disableNameSuffixHash in kustomization.yaml).
The Job runs scripts/preupgrade.sh:
- Preflight. With no
deployment/mattermost(a fresh cluster) it passes without a backup. Otherwise it records the running image, replica count and chart version. - Nothing to upgrade? When the running image's version equals
TARGET_VERSION, the gate logsMattermost already runs <version> (<image>): nothing upgrades, nothing to back upand passes: it stops nothing and leavesmattermost-backup-latestas it is. The annotationplatform.skatzi.com/preupgrade-forceondeployment/mattermostoverrides this (see Forcing a backup). - Checks.
mattermost-db'sContinuousArchivingcondition must beTrue. If WAL archiving is broken, the Backup cannot complete, so the Job fails here, before any downtime. Without the claimmattermost-data(a Mattermost from before the file volume) it backs up the database only and records no files. Otherwise it creates the work volumemattermost-preupgrade-work(20 GiB). - Stop writes. Scales
deployment/mattermostto 0 and waits for its pods to go. Mattermost has no read-only mode. - Backup. Creates the CNPG
Backupmattermost-db-preupgrade-<timestamp>(method: plugin, annotated with the running and target versions). While it runs, the podmattermost-preupgrade-dump(templates/files-dump-pod.yaml,files.sh dump) mountsmattermost-dataread-only and writesfiles.tar(withoutlost+found) andfiles.env(CREATED,COUNTof regular files,SHA256of the archive) to the work volume. The gate deletes that pod, which frees theReadWriteOncevolume for Mattermost, and waits up to an hour for the Backup to becompleted.failedfails the Job with the Backup's error. - Resume. Scales Mattermost back. Downtime lasts only for the backup and the archive.
- Upload. The pod
mattermost-preupgrade-upload(templates/files-upload-pod.yaml,files.sh upload) uploads the archive, then prunes older gate file backups. It keeps all from the last 30 days and always the newest three, as Gitea's gate does. Then the work volume is deleted. - Verify (the restore check), with exactly this backup: the copy
cnpg-drill/mattermost-preupgradeis recovered withrecoveryTarget: {backupID: <the Backup's status.backupId>, targetImmediate: true}, so it stops where the backup ended and replays none of the writes made after Mattermost resumed. The files are restored from the prefix just uploaded, and the running image is started on both. - Record. Writes ConfigMap
mattermost/mattermost-backup-latest(BACKUP,BACKUP_ID,FILES(the files' prefix, empty without a file volume),CREATED,VERSION,IMAGE,CHART_VERSION,TARGET_VERSION). Only a verified backup is recorded; the rollback restores what it names. A forced backup then removes the force annotation.
Whether a step succeeds or fails, a trap deletes the dump and upload pods, scales Mattermost back, and deletes the work volume, the copy, its files and its pod.
On failure the Job fails (backoffLimit: 0, deadline 6 hours, as Gitea's), mattermost-preupgrade is not Ready, mattermost stays on the old version, and the Flux alert taskbase-platform turns the failed Kustomization into a Taskbase task. To retry after a fix:
kubectl --context admin@mgmt-cluster -n mattermost logs job/mattermost-preupgrade
kubectl --context admin@mgmt-cluster -n mattermost delete job mattermost-preupgrade
flux --context admin@mgmt-cluster reconcile kustomization mattermost-preupgrade
The gate runs whenever the Job is (re)created, not only for version changes: on first deploy and after a manual delete too. It takes a backup, and costs a few minutes of Mattermost downtime, only when Mattermost runs a version other than TARGET_VERSION, or when the backup is forced.
scripts/test_preupgrade.py runs the gate against a fake kubectl: it passes without stopping Mattermost when nothing upgrades, even with WAL archiving broken, and runs in full on an upgrade or a forced backup.
Forcing a backup of the running version¶
To back up the version Mattermost already runs, for a first backup on a new cluster or before a risky change the gate does not cover, annotate the Deployment, then rerun the gate. Mattermost is down for a few minutes, as on an upgrade:
kubectl --context admin@mgmt-cluster -n mattermost annotate deployment mattermost platform.skatzi.com/preupgrade-force=true
kubectl --context admin@mgmt-cluster -n mattermost delete job mattermost-preupgrade
flux --context admin@mgmt-cluster reconcile kustomization mattermost-preupgrade
The gate logs Forced by the annotation … and runs every step. Once the backup is verified and recorded it removes the annotation (the Role mattermost-preupgrade may patch deployment/mattermost for this), so the next gate on the same version passes without a backup again. A failed gate leaves the annotation, so a retry is forced too. Helm leaves an annotation it did not set in place across upgrades, and an annotation on the Deployment's metadata starts no rollout. The rollback never restores a forced backup after an upgrade: the upgrade's gate replaces it with its own first.
Daily file backup¶
Between upgrades, which may be weeks apart, the gate's copy is the only one of the files off the volume. The database has a daily CNPG ScheduledBackup and continuous WAL, so the CronJob mattermost/mattermost-files-backup backs up the files every day at 04:00 UTC, without stopping Mattermost:
- Dump. The init container
dump(files.sh dump, the gate's step) mountsmattermost-dataread-only and writesfiles.tarandfiles.envto an ephemeral 20 GiB work volume. - Upload. The container
upload(files.sh upload) uploads them to<cluster>/mattermost/daily/<dump time>/, as the gate does (1 GiB parts with Content-MD5,files.envlast). It then prunes the older daily backups by the gate's rule: all from the last 30 days and always the newest three.
Same node. The volume is ReadWriteOnce, which allows several pods on the node that has it attached (Kubernetes: access modes). A required podAffinity to Mattermost's server pod puts the backup pod on that node. A CSI snapshot is not possible: the Hetzner CSI driver advertises no CREATE_DELETE_SNAPSHOT capability (ControllerGetCapabilities in internal/driver/controller.go). While the pod runs, the volume cannot move to another node: a Mattermost pod rescheduled elsewhere at that time waits for the backup to end. While Mattermost is scaled to 0 (the gate, a rollback), the pod stays Pending until Mattermost is back, and the Job's 3-hour deadline ends it otherwise.
Mattermost keeps running, so the dump may race with uploads. Mattermost's local file store writes an upload straight into its final path (os.OpenFile with O_TRUNC, then io.Copy; writeFileLocally in Mattermost server/platform/shared/filestore/localstore.go), and it does not change a file once written. So a daily archive can only hold a partial copy of an upload that was in flight at 04:00, or miss a file deleted during the dump. GNU tar warns (file changed as we read it) and exits 1, which files.sh dump accepts; any other error fails it. COUNT counts the regular files in the archive, not on the volume, so the restore's count check still holds. The next day's backup has that upload complete, and the gate, which stops Mattermost, stays a consistent copy for the rollback.
Space. Each daily backup is a full archive. The bucket's object lock keeps pruned versions for 31 days, so the store holds about 31 copies of the files whatever the prune does. That is up to 310 GiB at the volume's 10 GiB, and ObjectStorageApproachingIncludedCapacity warns before the included capacity runs out.
A finished Job is not kept, because its pod holds the 20 GiB work volume. A failed one is (failedJobsHistoryLimit: 1), and KubeJobFailed reports it, as for the Gitea and Harbor drills. The fixed runs do not replace it, so once the cause is fixed, delete it (kubectl --context admin@mgmt-cluster -n mattermost delete job <name>) and the alert clears; its pod and log are already gone after a deadline. To run one now: kubectl --context admin@mgmt-cluster -n mattermost create job --from=cronjob/mattermost-files-backup mattermost-files-backup-manual.
scripts/test_files.py tests the dump, the upload's naming and prune, and which backup fetch picks, against a fake store; CI runs it with the smoke check's tests (below).
The restore check¶
The gate and the drill share one restore check (restore_check in scripts/lib.sh):
- Restore. Creates the CNPG
Cluster<copy>incnpg-drillwithmattermost-db's PostgreSQL image and size, bootstrapped byrecoveryfrom thebackup-storeObjectStore(serverName: mattermost), withdatabase: mattermostandowner: mattermost. CNPG generates the secret<copy>-appand sets the owner's password from it once recovery is complete (CNPG: Recovery). The copy has no WAL archiver, so it never writes into the store. It waits up to 40 minutes for it to beReady. - Query.
SELECT count(*) FROM usersthroughpsqlin the copy's pod must return at least 1. - Files. Creates the volume
<copy>-files(10 GiB, the size ofmattermost-data). If the backup has files, the pod<copy>-files(templates/files-restore-pod.yaml) downloads them (the drill passes several prefixes, andfiles.sh fetchtakes the newest complete one) into an ephemeral work volume and checks the archive's SHA-256 (files.sh fetch). It then unpacks them into<copy>-files, where the number of regular files must equalCOUNTfrom the dump (files.sh restore). Without files the volume stays empty, and the log says so. This runs in a pod of its own because the network policy below keeps the restored Mattermost away from the backup store. - Start and smoke (
templates/restore-pod.yaml, pod<copy>-mattermost): the Mattermost image that made the backup runs as a sidecar on the copy, with<copy>-filesat/mattermost/dataand the sameMM_FILESETTINGS_*as production. Thesmokecontainer then runssmoke.py check <version>against127.0.0.1:8065(see the smoke check). Its status check writes, reads and removes a test file in the restored file store, so it fails if Mattermost cannot use the files.
The copy holds production's configuration, because Mattermost keeps it in the database. Two things keep it from acting as production:
- Settings.
MM_CONFIGandMM_SQLSETTINGS_DATASOURCEpoint at the copy. The second is needed because the stored configuration names production's database (Mattermostconfig/database.gokeeps the storedSqlSettings.DataSource). Mail and push notifications, outgoing webhooks, plugins, background jobs, clustering and telemetry are switched off throughMM_*environment overrides. The DSN is built from the<copy>-apppassword by Kubernetes$(VAR)expansion: the image is distroless, without a shell. CNPG generates its passwords from letters and digits only, so they need no escaping in the URL. - Network. The
CiliumNetworkPolicycnpg-drill/mattermost-restorelets pods labelledapp.kubernetes.io/name: mattermost-restorereach only kube-dns and the copies' PostgreSQL pods (cnpg.io/clustermattermost-preupgradeormattermost-drill) on 5432. Ingress is not restricted, so the kubelet's probes work.
Weekly restore drill¶
The CronJob cnpg-drill/mattermost-restore-drill runs on Sundays at 05:00 UTC (scripts/drill.sh). It runs the restore check into the copy mattermost-drill with the latest database backup and all archived WAL, the path a disaster recovery takes. It adds the newest file backup and starts the Mattermost image that runs in production. The drill passes <cluster>/mattermost/daily/ and the gate's FILES from mattermost-backup-latest. files.sh fetch takes the newest complete daily backup (one with files.env) and compares it with the gate's by the time stamp their names start with, and the fetch log names the one it restored. With no file backup at all, the drill fails. On success it writes ConfigMap cnpg-drill/mattermost-drill (lastSuccess, pod, image, version, files: the prefixes it chose from). It replaces the CNPG drill drill-mattermost, which only ran the query.
The files are up to a day older than the database, which reaches the latest WAL: on Sunday the drill restores the 04:00 backup together with the database as of 05:00. Messages that refer to files uploaded in between restore without those files. A disaster recovery has the same gap, up to a day.
The drill Job has a deadline of 4 hours (activeDeadlineSeconds: 14400), above the script's own waits so that a slow but healthy restore ends with the script's message rather than a kill: up to 35 minutes to delete a copy and its files left by an earlier run, 40 for the restored copy to be Ready, 60 for the files, 30 for the Mattermost smoke check, and 35 to delete the copy and its files on exit, 200 minutes in all.
It lives in cnpg-drill, so CNPGRestoreDrillFailed watches it with the other drills (CloudNativePG: alerts).
PR evidence for a Mattermost upgrade cites the last passing drill:
kubectl --context admin@mgmt-cluster -n cnpg-drill get configmap mattermost-drill -o jsonpath='{.data}'
kubectl --context admin@mgmt-cluster -n cnpg-drill get cronjob mattermost-restore-drill -o jsonpath='{.status.lastSuccessfulTime}'
To run a drill now: kubectl --context admin@mgmt-cluster -n cnpg-drill create job --from=cronjob/mattermost-restore-drill mattermost-restore-drill-manual.
The smoke check¶
scripts/smoke.py checks GET /api/v4/system/ping?get_server_status=true. Mattermost answers it without a session, with 500 unless every status is OK; with get_server_status=true it also writes to and deletes from its database and tests its file store (api4/system.go, getSystemPing). Every API response carries X-Version-Id: <version>.<build>.<config hash>.<licensed> (web/handlers.go), and the check passes when its first three fields equal the expected version. It retries every 15 seconds until DEADLINE_SECONDS.
| Mode | Used by | Also |
|---|---|---|
check <version> |
the restore check, the rollback's last step | nothing |
upgrade <version> |
mattermost-smoke |
lifts a rollback hold, starts or re-arms the rollback (below) |
To test it: python3 -m unittest discover -s components/mattermost/backup/scripts -p 'test_*.py' (CI runs it with every components/**/test_*.py). On macOS it needs GNU tar and coreutils and a TMPDIR without spaces; see Running Component Tests Locally.
Post-upgrade smoke check and rollback¶
Renovate PR merged (image tag, both TARGET_VERSIONs and the chart bumped)
└─▶ mattermost-preupgrade: backs up the old version, writes mattermost-backup-latest
├─▶ mattermost: HelmRelease upgrade (Helm rollback as remediation)
└─▶ mattermost-postupgrade: Job mattermost-smoke, recreated for the new TARGET_VERSION
├─ Mattermost reports TARGET_VERSION within 45m ─▶ pass
└─ it does not ─▶ resume Job mattermost-rollback, fail
├─▶ mattermost-postupgrade not Ready ─▶ Flux alert ─▶ Taskbase task: revert the upgrade in Git
└─▶ mattermost-rollback: guard ▸ hold ▸ restore a copy and dump it ▸ stop ▸ replace the files ▸ replace the database ▸ pin ▸ resume ▸ check
mattermost-smoke runs smoke.py upgrade <TARGET_VERSION> against mattermost.mattermost.svc:8065 for 45 minutes. That covers the lag from the gate to the upgrade, the upgrade and its remediation. mattermost-postupgrade dependsOn mattermost-preupgrade, not mattermost: a broken upgrade leaves mattermost not Ready, and Flux would never apply a dependent of it (Gitea rollback explains this in full).
On failure it resumes mattermost-rollback and fails. The Flux alert turns the failed mattermost-postupgrade into a Taskbase task: revert the whole upgrade commit, so mattermostApp.image.tag, both TARGET_VERSIONs and chart.spec.version are back at VERSION and CHART_VERSION of mattermost-backup-latest (also on the hold's annotations), and record what failed.
The rollback Job¶
mattermost/mattermost-rollback is deployed suspended with kustomize.toolkit.fluxcd.io/ssa: IfNotPresent, as Gitea's is: Flux creates it and never changes it, so it never re-suspends a running rollback. Its rollback init container runs scripts/rollback.sh:
- Guard, before anything changes.
TARGET_VERSIONinmattermost-backup-latestmust equal the HelmRelease'smattermostApp.image.tag, andCREATEDmust be later than the start of themattermost-preupgradeJob. On a fresh cluster, or when Mattermost already ranTARGET_VERSION, the gate takes no backup, and the ConfigMap would still name an older one. It also runsSELECT 1inmattermost-db's primary, to prove it mayexecthere before Mattermost is stopped. - Hold. Suspends the
mattermostFlux Kustomization, annotatedplatform.skatzi.com/mattermost-rollback-pin: <version>andplatform.skatzi.com/mattermost-rollback-pin-chart: <chart version>, then themattermostHelmRelease, with the field managermattermost-rollback. Then it waits until Helm has no action in flight. - Restore a copy and dump it. Restores
BACKUP_IDintocnpg-drill/mattermost-rollback(stopping where the backup ended, as the gate does), counts its users and runspg_dump --format=custominto the Job'sworkvolume, then deletes the copy. Up to here nothing live has changed. - Stop. Scales
deployment/mattermostto 0 and waits for its pods. - Replace the files, if the backup has any (
FILES). The podmattermost-rollback-files(templates/files-rollback-pod.yaml) first downloads the archive and checks its SHA-256 in an init container, so a failed download changes nothing. Then it moves everything onmattermost-dataexceptlost+foundtomattermost-rollback-aside:<stamp>/, unpacks the backup and checks the file count (files.sh restore). The rollback creates the aside volume (10 GiB) if it does not exist yet. A backup without files (taken before the file volume) leaves the files as they are. - Replace the database, as
postgresinmattermost-db-1: ends the remaining sessions, renamesmattermosttomattermost_rollback_<stamp>, creates an emptymattermostowned bymattermost, and runspg_restore --no-owner --no-acl --role=mattermost --exit-on-error, so the objects belong tomattermost. The user count must equal the copy's.mattermost-dbkeeps archiving WAL, so the restored state is in the store too. - Pin and resume. One patch sets the HelmRelease's
chart.spec.versionandvalues.mattermostApp.image.tagto the backup's and clearssuspend. Once it is Ready at that generation, and only if the Deployment runs the backup's version, it scales Mattermost back up and waits for it.
The check container then runs smoke.py check <restored version>; the Job succeeds only if Mattermost reports it.
The hold ends as it does for Gitea (the hold, and how it ends): once Git carries the pinned version again, the revert recreates the gate and mattermost-smoke. Mattermost already runs that version, so the gate passes without a backup, and mattermost-backup-latest keeps naming the backup that was restored. mattermost-smoke then removes the annotations and the suspension, checks Mattermost and deletes the finished rollback Job so that Flux recreates it suspended. While Git carries yet another version, mattermost-smoke fails with Mattermost is held at <version> (chart <chart version>) and starts no rollback.
Data¶
- Lost: writes and uploads made between the gate's backup and the upgrade, because the gate resumes Mattermost after the backup. They are in the failed database and the failed files that the rollback keeps. The rollback restores the gate's files, not a daily backup, because they match the database it restores.
-
Kept until a person removes it: the failed database
mattermost_rollback_<stamp>inmattermost-db. It shares the 10 GiB volume with the restored one, so drop it once the revert is merged and nothing needs to be recovered from it: -
Kept until a person removes it: the failed files, in
<stamp>/on the volumemattermost-rollback-aside. The next rollback adds its own directory, so delete the volume once nothing needs to be recovered from it:kubectl --context admin@mgmt-cluster -n mattermost delete pvc mattermost-rollback-aside.
RBAC¶
| Account | Where | Can |
|---|---|---|
mattermost-preupgrade |
mattermost |
read and scale deployment/mattermost and remove its force annotation, create, read and delete pods and PVCs, read pod logs, read the HelmRelease and the Cluster mattermost-db, create and read Backups, write ConfigMap mattermost-backup-latest |
none (automountServiceAccountToken: false) |
mattermost |
the daily file backup's pod mounts mattermost-data, its work volume and the backup-store Secret, and calls no Kubernetes API |
mattermost-restore-drill |
mattermost |
read deployment/mattermost, the Cluster mattermost-db and ConfigMap mattermost-backup-latest |
all three accounts (mattermost-restore) |
cnpg-drill |
create, read and delete Clusters, pods and PVCs, read pod logs, exec (for psql and pg_dump), write ConfigMap mattermost-drill |
mattermost-smoke |
mattermost, flux-system |
get, patch and delete the Job mattermost-rollback; get and patch the Kustomization mattermost |
mattermost-rollback |
mattermost, flux-system |
get/patch the HelmRelease; read and scale deployment/mattermost; create, read and delete pods and read their logs; read and create PVCs; exec into mattermost-db-1 only; read the Cluster, ConfigMap mattermost-backup-latest and Job mattermost-preupgrade; get/patch the Kustomization mattermost |
Creating pods in cnpg-drill lets these accounts mount the Secrets there: the copies' generated credentials and backup-store, which the copies need anyway. mattermost-preupgrade and mattermost-rollback can create pods in mattermost too, for the file pods, so they can also mount the Secrets there: backup-store, which those pods need, and mattermost-db-secret.
Checking it on the cluster¶
kubectl --context admin@mgmt-cluster -n mattermost get job mattermost-preupgrade mattermost-smoke mattermost-rollback # rollback suspended
kubectl --context admin@mgmt-cluster -n mattermost get configmap mattermost-backup-latest -o jsonpath='{.data}'
kubectl --context admin@mgmt-cluster -n mattermost get backups.postgresql.cnpg.io
kubectl --context admin@mgmt-cluster -n mattermost logs job/mattermost-rollback --all-containers --prefix # after a rollback
kubectl --context admin@mgmt-cluster -n flux-system get kustomization mattermost \
-o jsonpath='{.spec.suspend} {.metadata.annotations.platform\.skatzi\.com/mattermost-rollback-pin}' # the hold
A rollback that is not suspended and not running has already run. Until that Job is deleted, a failed smoke check starts no rollback and says so. Re-arm it with kubectl --context admin@mgmt-cluster -n mattermost delete job mattermost-rollback && flux --context admin@mgmt-cluster reconcile kustomization mattermost-postupgrade.
Manual fallback¶
When mattermost-rollback refuses or fails, its log names the step, and the state it leaves is safe to pick up by hand:
- Guard refused: nothing has changed. Choose the backup (
kubectl --context admin@mgmt-cluster -n mattermost get backups.postgresql.cnpg.io,.status.backupId) and follow the steps below. - Failed before the stop: the hold is in place; Mattermost and its database are untouched.
- Failed after the stop: the log shows how far it got. If the pod
mattermost-rollback-filesfailed infetch, the files are untouched. If it failed inrestore, the failed files are inmattermost-rollback-aside:<stamp>/(Failed files kept in …) andmattermost-dataholds part of the backup. After that come the rename (Failed database kept as …) andpg_restore.
By hand, with BACKUP_ID, VERSION and CHART_VERSION from mattermost-backup-latest or the chosen Backup:
- Hold:
flux --context admin@mgmt-cluster suspend kustomization mattermost && flux --context admin@mgmt-cluster suspend helmrelease mattermost -n mattermost. - Restore a copy as in CloudNativePG: restoring by hand, with
recoveryTarget: {backupID: <BACKUP_ID>, targetImmediate: true}, and dump it:kubectl --context admin@mgmt-cluster -n <ns> exec <copy>-1 -c postgres -- pg_dump --format=custom -d mattermost > mattermost.pgdump. kubectl --context admin@mgmt-cluster -n mattermost scale deployment mattermost --replicas=0. If the backup has files (FILES), restore them as step 5 of the rollback does: rendertemplates/files-rollback-pod.yamlwithNAME,PREFIX=<FILES>andSTAMP, after creatingmattermost-rollback-asidefromtemplates/pvc.yaml. Then rename, recreate and restore the database exactly as step 6 does (scripts/rollback.sh).- Pin: set
mattermostApp.image.tag, bothTARGET_VERSIONs andchart.spec.versionin Git toVERSIONandCHART_VERSION(revert the upgrade commit), thenflux --context admin@mgmt-cluster resume helmrelease mattermost -n mattermost && flux --context admin@mgmt-cluster resume kustomization mattermost. If an automatic hold is in place, remove its annotations first:kubectl --context admin@mgmt-cluster -n flux-system annotate kustomization mattermost platform.skatzi.com/mattermost-rollback-pin- platform.skatzi.com/mattermost-rollback-pin-chart-.