Chapter 02Lesson 05~45 minutes

Snapshots, Lab Reset Strategies, and Course Conventions

A safe lab is not one where nothing breaks. It is one where breakage is intentional, contained, observable, and recoverable. This lesson defines the reset discipline and course conventions used throughout the remaining Linux chapters.

BeginnerRecoveryCourse workflow

Learning objectives

By the end of this lesson

  • Differentiate snapshots, backups, clones, exports, and reproducible rebuilds.
  • Create a layered recovery strategy for VMs, WSL, containers, and cloud labs.
  • Verify a restored environment rather than assuming rollback succeeded.
  • Apply consistent course paths, naming, command-risk labels, and evidence rules.
  • Prepare a clean Chapter 2 baseline before beginning command-line administration.

1. Recovery is part of the lab design

Snapshots are convenient, but they are not the same as independent backups or reproducible builds. A robust lab uses several recovery layers because each protects against different failures.

Snapshot

Fast checkpoint

Captures VM state or disk state within the virtualization platform. Excellent for rollback, but often dependent on the original VM and storage.

Backup or export

Independent copy

Stores important files or a machine archive separately so recovery can survive loss of the working instance.

Rebuild definition

Repeatable creation

Documents or automates packages, configuration, users, and verification so the environment can be reconstructed cleanly.

2. A disciplined checkpoint lifecycle

Every risky lab follows the same recovery loop
flowchart TD
  B["Verify clean baseline"] --> C["Create named checkpoint"]
  C --> E["Run bounded experiment"]
  E --> V["Verify expected result"]
  V --> K{"Keep the state?"}
  K -->|"Yes"| N["Document new baseline"]
  K -->|"No or failed"| R["Restore checkpoint"]
  R --> Q["Run reset verification"]
  Q --> B

A checkpoint without a verification procedure is only a hope. Record what “clean” means: release, kernel, hostname, network mode, disk usage, failed services, package state, and expected lab files.

3. Recovery methods by environment

PlatformFast resetIndependent recovery
Virtual machineHypervisor snapshot or linked cloneFull clone, exported appliance, configuration notes, file backup
WSL 2Restore from a duplicate/imported distribution or recreate working fileswsl --export archive plus project backup
ContainerDelete and recreate from immutable image and commandVersioned Dockerfile/Containerfile, compose file, and persistent-volume backup
Cloud VMImage/snapshot or instance replacementInfrastructure as code, configuration automation, external data backup
Browser labRestart the sessionExport scripts and notes to a trusted repository

4. Snapshot rules for the primary VM

  • Shut down the guest for the most conservative filesystem-consistent snapshot unless the platform explicitly provides a trusted application-consistent workflow.
  • Name checkpoints by sequence, purpose, and date—not “snapshot1”.
  • Keep a small number of meaningful checkpoints; long chains consume storage and complicate recovery.
  • Do not treat snapshots as archival backup. Hypervisor metadata or the entire host disk can still fail.
  • Before reverting, preserve any logs or files needed to understand the failed experiment.
Recommended checkpoint names

00-clean-install-updated
01-chapter02-lab-ready
02-before-permissions-labs
03-before-storage-partitioning
04-before-firewall-hardening

Record beside each checkpoint:
- guest shutdown or live state
- distribution and kernel
- reason for creation
- expected restore test
- files that exist outside the snapshot

5. DevOps Academy Linux lab conventions

ConventionRequired patternPurpose
Lab root~/devops-academy/linux/chapterNN/lessonNNPredictable paths and easy cleanup
Evidence firstCapture current state before changing itSupports comparison and rollback
Least privilegeUse sudo only for the command that requires itReduces accidental system-wide changes
Explicit variablesAssign and print target paths before destructive commandsPrevents expansion and copy/paste mistakes
VerificationEvery change has a test and expected evidenceCompletion means observed state, not command exit alone
CleanupRemove temporary resources or restore checkpointKeeps later lessons reproducible

6. Command risk labels used in later lessons

READ

Inspection only

Designed to observe state, although reading sensitive files can still require authorization.

USER

Changes your lab files

Creates or modifies content under the course directory without administrative privilege.

SYSTEM

Changes host configuration

Requires careful review, usually sudo, and a verification plus rollback plan.

DESTRUCTIVE

Can remove data or connectivity

Must be executed only in the intended disposable environment after a checkpoint.

Risk depends on context

rm inside a dedicated temporary directory and rm against an expanded root path use the same command but have radically different consequences. Always inspect resolved targets.

7. Safe shell patterns for labs

# Establish a predictable lab directory.
chapter="02"
lesson="05"
lab="$HOME/devops-academy/linux/chapter${chapter}/lesson${lesson}"
mkdir -p -- "$lab"
printf 'Lab directory: %q\n' "$lab"
cd -- "$lab"

# Refuse to continue if the path is not under the expected course root.
case "$PWD" in
  "$HOME/devops-academy/linux/"*) ;;
  *) printf 'Refusing unexpected directory: %s\n' "$PWD" >&2; exit 1 ;;
esac

# Capture evidence before modifying a file.
cp -a -- example.conf "example.conf.before-$(date +%Y%m%d-%H%M%S)" 2>/dev/null || true

# Preview a generated target list before any removal.
printf '%s\n' ./*.tmp
# Only after verifying the list would a later lesson remove those exact files.

Quotes, -- option terminators, explicit paths, and guard conditions are not decoration. They reduce ambiguity when variables, filenames, or copied commands behave unexpectedly.

8. Create a machine-readable baseline manifest

A simple text manifest makes resets testable. It is not a full backup, but it records enough state to detect an incomplete restore.

baseline_report() {
  printf 'timestamp=%s\n' "$(date --iso-8601=seconds 2>/dev/null || date)"
  printf 'hostname=%s\n' "$(hostname)"
  printf 'kernel=%s\n' "$(uname -r)"
  printf 'architecture=%s\n' "$(uname -m)"
  printf 'boot_id=%s\n' "$(cat /proc/sys/kernel/random/boot_id)"
  printf 'virtualization=%s\n' "$(systemd-detect-virt 2>/dev/null || printf unknown)"
  printf 'failed_units=%s\n' "$(systemctl --failed --no-legend 2>/dev/null | wc -l)"
  printf 'root_usage=%s\n' "$(df -P / | awk 'NR==2 {print $5}')"
  printf 'primary_route=%s\n' "$(ip route show default | head -n 1)"
}

lab="$HOME/devops-academy/linux/chapter02/lesson05"
mkdir -p "$lab"
baseline_report > "$lab/chapter02-baseline.env"
cat "$lab/chapter02-baseline.env"

The boot ID changes after reboot and should not be compared as a fixed identity. It is useful evidence that a reboot or restore actually occurred. Define which fields must match and which should only be present.

9. Reset verification procedure

01Restore or recreate

Revert the snapshot, import the WSL archive, recreate the container, or reprovision the VM.

02Confirm identity

Distribution, version, kernel, hostname, virtualization, and intended user.

03Confirm health

Boot completed, time is correct, network route exists, and failed services are explained.

04Confirm cleanliness

Temporary users, packages, mounts, firewall rules, and lesson artifacts from the failed experiment are absent.

05Run one smoke test

Package metadata refresh, DNS lookup, local file write, and optional SSH access.

10. Hands-on lab: prove that your reset works

Perform this only after creating the Chapter 2 checkpoint. The exercise changes a file in your home directory, verifies it, restores the checkpoint, and confirms the marker disappeared.

lab="$HOME/devops-academy/linux/chapter02/lesson05"
mkdir -p "$lab"
marker="$lab/reset-test-marker.txt"

printf 'created_at=%s\n' "$(date --iso-8601=seconds 2>/dev/null || date)" > "$marker"
printf 'marker=%s\n' "$marker"
cat "$marker"

# STOP HERE.
# 1. Confirm the marker exists.
# 2. Restore the Chapter 2 clean checkpoint using the platform UI or safe
#    platform-specific restore process.
# 3. Reopen the terminal and run the verification commands below.

test ! -e "$marker" && printf 'PASS: marker removed by reset\n' || {
  printf 'FAIL: marker still exists after reset\n' >&2
  exit 1
}

cat "$HOME/devops-academy/linux/chapter02/lesson05/chapter02-baseline.env" 2>/dev/null || true
systemctl --failed --no-pager 2>/dev/null || true
ip route show default

Verification checklist

11. Common recovery mistakes

Calling a snapshot a backup

A snapshot may depend on the original VM files and storage. Maintain an independent copy or reproducible build path for important work.

Never testing restore

An untested recovery procedure can fail precisely when it is needed. Chapter 2 ends with a real reset test.

Keeping every snapshot forever

Long chains consume storage, complicate dependencies, and make it unclear which state is authoritative.

Restoring before preserving evidence

When the failure matters, capture logs, commands, timestamps, and changed files before rollback destroys the context.

12. Knowledge check

Question 1. Why is a VM snapshot not automatically an adequate backup?

Question 2. What proves that a reset procedure works?

Question 3. What is the course rule before a destructive or connectivity-changing lab?

13. Chapter summary

Chapter 2 established a safe Linux laboratory: a deliberate distribution choice, a complete VM, a productive WSL option, disposable environments for bounded exercises, and a tested reset strategy. The remaining course can now include controlled system changes because the learner has a known baseline and recovery procedure.

Next chapter

Terminal, Shell, and Navigation

Chapter 3 begins by separating terminals, TTYs, shells, and command syntax before introducing navigation and stream behavior.

14. Further reading

  • Your hypervisor’s official snapshot, clone, and export documentation.
  • Microsoft WSL export/import and distribution-management documentation.
  • Cloud-provider image, snapshot, backup, and infrastructure-as-code documentation.
  • GNU Bash Reference Manual — quoting, expansion, redirection, and shell safety.
  • Linux manual pages for cp, test, date, systemctl, ip, and systemd-detect-virt.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.