Backup and restore: tar, rsync, LVM snapshots
Sign in to read this lesson
A disk fails, someone deletes the wrong folder, ransomware gets in. After that the only thing that saves the work is a tested backup. In this lesson we learn tar archives, backups to another server with rsync, consistent copies with LVM snapshots, database dumps, and most important of all — testing the restore.
What you will learn
- The 3-2-1 rule: 3 copies, 2 different media, 1 copy elsewhere. A copy on the same disk is not a backup.
tar -czf archive.tar.gz --selinux --acls --xattrs folder— an archive with permissions, ACLs and SELinux contexts;tar -tzflists,tar -xzf ... -C targetextracts.rsync -aAX --delete source/ server:target/sends only what changed; with--link-dest, daily copies that look complete but take little space.- An LVM snapshot (
lvcreate -s) freezes a file system at one moment; an XFS snapshot is mounted with-o ro,nouuidand removed withlvremoveafterwards. - Do not copy database files while it runs — use
mysqldump --single-transaction. A backup whose restore was never tested is not a backup.
The lesson has 5 key points, an explanation and 5 questions. It opens with a package.