Skip to main content
RunBook Academy

LinuxXXXIII · Fleet Patch ManagementRollback

Rollback strategies - safe deployment reversals

Intermediate⏱ ~10 minAnsiblekubectldnf historyapt

What you'll learn

  • Roll back a failed package update
  • Revert a configuration change
  • Reverse a container deployment
  • Test rollback in staging

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

Every deployment should have a tested rollback procedure. If you cannot roll back, the change is a one-way door.

Package rollback

RHEL family

# View history - find the transaction id
sudo dnf history list

# Confirm what that transaction actually did
sudo dnf history info 42

# Invert exactly that transaction
sudo dnf history undo 42

# Invert the most recent transaction
sudo dnf history undo last

dnf history records every transaction, including the packages and versions involved.

Debian / Ubuntu

# Substitute your own values before running:
PACKAGE=nginx
OLD_VERSION=1.24.0-1

# What changed, from which version to which. history.log records the
# transaction; dpkg.log records individual package state transitions and is
# far harder to read under pressure.
grep -A3 '^Start-Date' /var/log/apt/history.log | tail -40

# Is the previous version still obtainable? Check BEFORE you need it.
apt-cache policy "$PACKAGE"
ls /var/cache/apt/archives/"$PACKAGE"_*.deb

# Downgrade, then freeze - a downgrade alone is undone by the next upgrade
sudo apt-get install -y --allow-downgrades "$PACKAGE"="$OLD_VERSION"
sudo apt-mark hold "$PACKAGE"
apt-mark showhold
dpkg -l "$PACKAGE" | tail -1        # confirm the version actually in place

RHEL’s dnf history undo is a genuine transaction reversal and is the closer analogue of a rollback; the section above covers it.

Configuration rollback

Configuration management tools make this easy:

# Substitute your own values before running:
COMMIT=a1b2c3d

# Ansible
ansible-playbook -i prod rollback.yml

# Revert a specific commit
git revert "$COMMIT"
ansible-playbook -i prod playbook.yml

The principle: configuration is in version control. Revert the change, apply the previous version.

Container rollback

# Substitute your own values before running:
PREVIOUS_TAG=v1.4.2

# Kubernetes
kubectl rollout undo deployment/myapp

# To a specific revision
kubectl rollout undo deployment/myapp --to-revision=3

# Docker
docker run myapp:"$PREVIOUS_TAG"

Container rollback is fast and safe; the previous image is known-good.

Database migration reversal

For schema changes, the rollback must include:

  • Revert the schema (drop new columns, drop new tables).
  • Revert the application code that used the new schema.

Test the rollback in staging:

  1. Apply migration.
  2. Verify application works.
  3. Roll back migration.
  4. Verify application still works (with old code).

A migration that cannot be rolled back is dangerous. Prefer forward-only migrations (add columns, never drop) for production.

Knowledge check

Knowledge check · 4 questions

  1. Q1. A dnf upgrade you ran ten minutes ago regressed the application. Which command backs out exactly that transaction?

  2. Q2. Container rollback requires testing in staging.

  3. Q3. Which of the following are valid rollback strategies? Select all that apply.

  4. Q4. Running `dnf history rollback 42` on a host that has had 30 transactions since #42 undoes all 30 of them.

Passing score: 75%. Answers are checked in this browser.