Sub topic 17
Capture a Snapshot or Backup of the Clean Baseline
Assume you have completed installation, verified networking and services, and can use sudo. This chapter uses “snapshot” for a point-in-time copy managed by a storage or virtualization layer. A backup is a separate copy that can be restored after the original disk or host is lost.
Snapshot or backup?
A snapshot is fast and convenient for testing a configuration change. It usually remains on the same storage system as the original disk, so it does not protect against that storage failing. A backup takes longer and should be stored on another disk, host, or cloud account.
| Method | Best use | Main limitation |
|---|---|---|
| Virtual machine snapshot | Quick rollback before changes | Often depends on the same host |
| LVM snapshot | Short-lived rollback on a Linux host | Uses space and is not an independent backup |
| File backup | Recover configuration and selected data | Does not automatically recreate the whole system |
Create a baseline only after updates, SSH access, firewall rules, and verification are complete. Record the image version, hostname, disk layout, and date with the backup.
Make a file-level baseline backup
A file-level backup of /etc preserves most system configuration. Save the package list too, so you can reinstall the same software on a replacement system.
sudo mkdir -p /var/backups/baseline
stamp=$(date -u +%Y%m%dT%H%M%SZ)
sudo tar --xattrs --acls --numeric-owner \
-czf "/var/backups/baseline/etc-${stamp}.tar.gz" /etc
if command -v dpkg-query >/dev/null; then
dpkg-query -W -f='${binary:Package}\t${Version}\n' |
sudo tee "/var/backups/baseline/packages-${stamp}.txt" >/dev/null
else
rpm -qa | sort |
sudo tee "/var/backups/baseline/packages-${stamp}.txt" >/dev/null
fi
sha256sum /var/backups/baseline/*"$stamp"* |
sudo tee "/var/backups/baseline/SHA256SUMS-${stamp}"Copy these files to storage outside the server. A backup left only under /var/backups will be lost with the server's disk.
Take a storage snapshot
For a virtual machine, use the provider or hypervisor's snapshot function. Shut down the guest, or stop important write-heavy services, when you need a consistent snapshot. A running snapshot may contain files from different points in time.
For an LVM system, first identify the logical volume and available space:
sudo lvs
sudo vgs
sudo lvcreate --snapshot --name root-baseline --size 2G /dev/vg0/root
sudo lvsReplace /dev/vg0/root with the actual root logical volume. The snapshot size is space reserved for changes made after the snapshot. Remove it after the rollback window ends:
sudo lvremove /dev/vg0/root-baselineNever treat an LVM snapshot as a permanent backup. Monitor its remaining space and copy important data elsewhere.
Baseline decision
Exercise
Why should a server have both a snapshot and an independent backup?
Show answer
A snapshot provides quick rollback, while an independent backup can survive loss or corruption of the original host storage.