Stop your backups from being corrupted by open database files

Backup & Recovery (Rsync/Tar/Dd)

Stop your backups from being corrupted by open database files

🧩 The Challenge

Backing up live MySQL or Postgres directories with rsync is a recipe for heartbreak because you almost always end up with an inconsistent state. I’ve restored databases from such backups only to find them completely mangled and unusable.

💡 The Fix

Use the –rsyncable-gzip option or, better yet, use lvm snapshots to create a point-in-time image before you even look at the files. This keeps the database consistent without locking the production service for hours.

lvcreate -L 10G -s -n backup_snap /dev/mapper/vg0-mysql_data
mount /dev/mapper/vg0-backup_snap /mnt/backup_source
rsync -aAXv /mnt/backup_source/ /backup/dest/
umount /mnt/backup_source
lvremove -f /dev/mapper/vg0-backup_snap

⚙️ Why It Works

Snapshots provide a frozen view of the disk at the exact moment of creation, allowing your backup tools to read data that isn’t actively changing. It’s the only sane way to handle high-traffic database volumes.

🚀 Pro-Tip: Always verify your backup integrity with a checksum or a dry-run restoration, otherwise you’re just writing to a digital graveyard.

Linux Tips & Tricks | © ngelinux.com | 9/5/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted