Table of Contents
- What Are Hot, Cold, and Warm Backups?
- Hot Backups (Live Backups)
- Definition & Use Cases
- Pros & Cons
- Linux Tools for Hot Backups
- Step-by-Step Example: LVM Snapshot Backup
- Step-by-Step Example: MySQL Hot Backup with
mysqldump
- Cold Backups (Offline Backups)
- Definition & Use Cases
- Pros & Cons
- Linux Tools for Cold Backups
- Step-by-Step Example: Cold Backup with
tar - Step-by-Step Example: Disk Cloning with
dd
- Warm Backups (Semi-Offline Backups)
- Definition & Use Cases
- Pros & Cons
- Linux Tools for Warm Backups
- Step-by-Step Example: MySQL Warm Backup with Read-Only Mode
- Comparing Hot, Cold, and Warm Backups
- Choosing the Right Backup Strategy
- Conclusion
- References
What Are Hot, Cold, and Warm Backups?
At their core, hot, cold, and warm backups differ in whether the system or application is running (and accepting writes) during the backup process:
- Hot Backup: The system/application is fully online and accepting read/write operations. Backups run in parallel with normal operations.
- Cold Backup: The system/application is completely offline (shut down). No read/write operations occur during the backup.
- Warm Backup: The system/application is partially offline—often in a read-only state or with write operations paused. It balances downtime and availability.
Hot Backups (Live Backups)
Definition
A hot backup (or “live backup”) is performed while the system, application, or database is actively running and processing user requests. It requires no downtime, making it ideal for 24/7 services like e-commerce platforms, email servers, or critical databases.
Use Cases
- High-availability systems (e.g., web servers, payment gateways).
- Databases with strict uptime SLAs (e.g., MySQL, PostgreSQL, MongoDB).
- Environments where even short downtime causes financial or reputational losses.
Pros & Cons
| Pros | Cons |
|---|---|
| No downtime for critical services. | Higher complexity (requires tools to handle in-flight data). |
| Continuous data protection. | Risk of inconsistent backups if not properly managed (e.g., files changing mid-backup). |
| Minimal disruption to users. | Higher resource usage (CPU, I/O) during backup. |
Linux Tools for Hot Backups
Linux offers robust tools to handle hot backups, even for dynamic data:
- rsync: With flags like
--inplace(overwrite files in place) or--partial(resume interrupted transfers),rsynccan back up live files. For databases, pair it with LVM snapshots (see example below). - LVM Snapshots: Logical Volume Manager (LVM) allows creating read-only snapshots of a live filesystem. The snapshot captures the state of the filesystem at creation time, enabling consistent backups without downtime.
- Database-Specific Tools:
mysqldump(MySQL/MariaDB): Use--single-transactionto create a consistent backup of an InnoDB database without locking tables.pg_dump(PostgreSQL): Creates hot backups by leveraging PostgreSQL’s transactional consistency.mongodump(MongoDB): Captures live backups of MongoDB databases.
Step-by-Step Example: LVM Snapshot for Hot Backup
Suppose you want to back up a live /var/www directory (hosting a website) using LVM.
-
Identify the LVM volume:
lvdisplay | grep "LV Path" # Example output: /dev/vg01/lv_www -
Create a snapshot of the live volume (allocates 10GB for changes during backup):
lvcreate --snapshot --size 10G --name lv_www_snap /dev/vg01/lv_www -
Mount the snapshot to access the frozen state:
mkdir /mnt/snap mount /dev/vg01/lv_www_snap /mnt/snap -
Back up the snapshot to an external drive or remote server:
rsync -av /mnt/snap/ /backup/www_backup_$(date +%F)/ -
Clean up: Unmount and delete the snapshot after backup:
umount /mnt/snap lvremove -y /dev/vg01/lv_www_snap
Step-by-Step Example: MySQL Hot Backup with mysqldump
To back up a live MySQL database without downtime:
- Use
--single-transactionfor InnoDB databases (ensures a consistent snapshot):mysqldump --single-transaction -u root -p my_database > /backup/my_database_$(date +%F).sql--single-transactionstarts a transaction, freezing the database state for the backup duration.- For MyISAM tables (which don’t support transactions), use
--lock-tablesinstead (locks tables read-only temporarily).
Cold Backups (Offline Backups)
Definition
A cold backup (or “offline backup”) is performed when the system, application, or database is fully shut down. Since no writes occur during the backup, the data is guaranteed to be consistent.
Use Cases
- Non-critical systems (e.g., internal wikis, development servers).
- Maintenance windows (e.g., monthly full system backups).
- Full disk/partition cloning (e.g., migrating to a new hard drive).
Pros & Cons
| Pros | Cons |
|---|---|
| Simple to implement (no need for complex tools). | Requires downtime (not suitable for 24/7 services). |
| Guaranteed consistency (no data changes during backup). | May disrupt users if scheduled during peak hours. |
| Lower resource usage (no competition with live traffic). | Risk of data loss if the system fails before the next backup. |
Linux Tools for Cold Backups
Cold backups rely on basic Linux utilities, as the system is offline:
- tar: Archives directories (e.g.,
/home,/etc) into compressed files. - rsync: Copies files to a remote server or external drive (no need for special flags since files are static).
- dd: Creates bit-for-bit copies of disks/partitions (e.g.,
dd if=/dev/sda of=/dev/sdbclones a disk). - cp: Simple file/directory copying (use
cp -ato preserve permissions and timestamps).
Step-by-Step Example: Cold Backup with tar
Back up a MySQL database directory after shutting down the service:
-
Stop the MySQL service:
systemctl stop mysql -
Verify the service is offline:
systemctl status mysql # Should show "inactive (dead)". -
Archive the database directory (e.g.,
/var/lib/mysql):tar -czvf /backup/mysql_cold_backup_$(date +%F).tar.gz /var/lib/mysql -
Restart the service:
systemctl start mysql
Step-by-Step Example: Disk Cloning with dd
Clone an entire disk (e.g., /dev/sda) to an external drive (/dev/sdb) while the system is offline (boot from a live USB):
-
List disks to identify the source and target:
lsblk # Example: /dev/sda (source), /dev/sdb (target, same size or larger). -
Clone the disk (this overwrites
/dev/sdb—use with caution!):dd if=/dev/sda of=/dev/sdb bs=4M status=progress
Warm Backups (Semi-Offline Backups)
Definition
A warm backup strikes a balance between hot and cold backups: the system or application is partially offline. For example, a database might be put into read-only mode (accepting reads but no writes), or write operations are paused temporarily. This ensures consistency without full downtime.
Use Cases
- Databases that can’t tolerate the resource overhead of hot backups.
- Systems with moderate uptime requirements (e.g., internal tools with off-peak hours).
- Environments where read-only mode is acceptable for short periods.
Pros & Cons
| Pros | Cons |
|---|---|
| Less complex than hot backups. | Some downtime (write operations are paused). |
| Consistent backups (no in-flight writes). | May require application changes (e.g., enabling read-only mode). |
| Lower resource usage than hot backups. | Users may experience delays or errors during write pauses. |
Linux Tools for Warm Backups
- Database Read-Only Mode: Most databases (MySQL, PostgreSQL) support read-only mode to pause writes.
- rsync + Read-Only Mounts: Mount filesystems as read-only temporarily to ensure consistency.
FLUSH TABLES WITH READ LOCK(MySQL): Locks tables read-only, allowingrsyncto back up data safely.
Step-by-Step Example: MySQL Warm Backup with Read-Only Mode
-
Put MySQL in read-only mode (prevents new writes):
mysql -u root -p -e "SET GLOBAL read_only = ON;" -
Flush in-memory data to disk to ensure consistency:
mysql -u root -p -e "FLUSH TABLES WITH READ LOCK;" -
Back up the data directory with
rsync:rsync -av /var/lib/mysql/ /backup/mysql_warm_backup_$(date +%F)/ -
Resume write operations:
mysql -u root -p -e "UNLOCK TABLES; SET GLOBAL read_only = OFF;"
Comparing Hot, Cold, and Warm Backups
To help you decide, here’s a side-by-side comparison of key factors:
| Factor | Hot Backup | Cold Backup | Warm Backup |
|---|---|---|---|
| Downtime | None | Full (system offline) | Partial (read-only/write pause) |
| Consistency | Requires tools (e.g., LVM, --single-transaction) | Guaranteed (no writes) | Guaranteed (writes paused) |
| Complexity | High (tools, monitoring) | Low (basic commands) | Moderate (read-only setup) |
| Resource Usage | High (CPU, I/O) | Low (system offline) | Moderate |
| Best For | 24/7 critical services | Non-critical systems, maintenance | Moderate uptime, lower overhead |
Choosing the Right Backup Strategy
Selecting between hot, cold, or warm backups depends on your environment’s unique needs:
- Prioritize uptime? Use hot backups (e.g., LVM snapshots,
mysqldump --single-transaction). - Can tolerate downtime? Use cold backups (e.g.,
tar,dd). - Need balance? Use warm backups (e.g., read-only mode +
rsync).
Other factors to consider:
- Data Criticality: How costly is data loss? Hot/warm backups reduce risk via frequent snapshots.
- Backup Window: Cold backups require scheduling during off-peak hours (e.g., midnight for internal tools).
- Resource Availability: Hot backups may strain I/O on low-end servers—opt for warm instead.
Conclusion
Hot, cold, and warm backups are foundational to Linux data protection, each with its own strengths. Hot backups keep critical systems online, cold backups simplify consistency with downtime, and warm backups balance the two. By aligning your choice with uptime requirements, complexity tolerance, and resource constraints, you can build a robust backup strategy that safeguards your data against loss.
Remember: No backup is complete without testing! Regularly restore backups to verify they’re usable—after all, a backup that fails to restore is no backup at all.