Zero-Downtime Server Backup Using LVM Snapshots and rsync (Production-Ready Guide)

Overview

Traditional server backups often cause performance degradation, file corruption, or downtime, especially when backing up live databases and active applications.

This guide demonstrates how to build a zero-downtime backup system using LVM snapshots combined with rsync, allowing you to back up live production servers safely without stopping services.

This method is widely used in enterprises but rarely documented clearly online.


Why LVM Snapshot Backups Matter


Supported Environments

Check LVM availability:

lsblk
vgs
lvs

Step 1: Verify LVM Layout

Identify volume group and logical volumes:

lsblk -f

Example output:

/dev/mapper/vg0-root
/dev/mapper/vg0-home

Check free space in volume group:

vgs

You must have free VG space for snapshots.


Step 2: Create LVM Snapshot

Create snapshot of root filesystem:

lvcreate \
--size 5G \
--snapshot \
--name root_snap \
/dev/vg0/root

Explanation


Step 3: Mount Snapshot Read-Only

Create mount point:

mkdir -p /mnt/root_snap

Mount snapshot:

mount -o ro /dev/vg0/root_snap /mnt/root_snap

Verify:

df -h | grep root_snap

Step 4: Backup Using rsync

Create backup directory:

mkdir -p /backup/server01

Run rsync:

rsync -aAXHv \
--numeric-ids \
--delete \
/mnt/root_snap/ \
/backup/server01/

Explanation


Step 5: Database-Safe Backup (Optional)

For MySQL/MariaDB:

mysqldump --single-transaction \
--routines --events \
--all-databases > /backup/db.sql

This ensures transaction-consistent backups without locking tables.


Step 6: Cleanup Snapshot

After backup completes:

umount /mnt/root_snap

Remove snapshot:

lvremove -y /dev/vg0/root_snap

⚠️ Never leave snapshots active for long periods.


Step 7: Automate with Script

Create backup script:

nano /usr/local/bin/lvm_backup.sh

Script:

#!/bin/bash

SNAP_NAME=root_snap
VG=vg0
LV=root
SNAP_SIZE=5G
MOUNT=/mnt/root_snap
BACKUP=/backup/server01

lvcreate -L $SNAP_SIZE -s -n $SNAP_NAME /dev/$VG/$LV
mount -o ro /dev/$VG/$SNAP_NAME $MOUNT

rsync -aAXHv --delete $MOUNT/ $BACKUP/

umount $MOUNT
lvremove -y /dev/$VG/$SNAP_NAME

Make executable:

chmod +x /usr/local/bin/lvm_backup.sh

Step 8: Schedule via Cron

crontab -e

Add:

0 2 * * * /usr/local/bin/lvm_backup.sh >> /var/log/lvm_backup.log 2>&1

Runs daily at 2 AM.


Step 9: Restore Procedure (Disaster Recovery)

Boot from rescue/live OS.

Mount target disk:

mount /dev/vg0/root /mnt/restore

Restore data:

rsync -aAXHv /backup/server01/ /mnt/restore/

Reinstall bootloader if required.


Best Practices


Common Mistakes


Conclusion

Using LVM snapshots with rsync, you can create zero-downtime, production-grade backups without expensive software or service disruption.

This approach is battle-tested in enterprise environments but rarely explained in a complete, practical guide.