Master Linux System Backup & Restore: Tar, Rsync, DD & Imaging Guide
This guide explains why regular backups are essential on Linux and provides step‑by‑step commands for creating full system archives with tar, cloning disks with dd, synchronizing files with rsync, and performing image‑based restores on new machines.
Frequent jokes about "deleting the database and running away" highlight the importance of proper backups; without them, a lost system cannot be recovered.
tar command
Backup the whole system on the local machine (ensure enough free space in the root directory).
cd /
# tar.gz format
tar cvpzf system_backup.tar.gz / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.gz --exclude=/mnt --exclude=/sys
# tar.bz2 format
tar cvpjf system_backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.bz2 --exclude=/mnt --exclude=/sys
# Restore system
cd /
# upload the backup file to the root directory
tar xvpfz system_backup.tar.gz -C /
# or
tar xvpfj system_backup.tar.bz2 -C /
# Directories to exclude when creating backup
mkdir proc
mkdir lost+found
mkdir mnt
mkdir sys/proc permissions: owner root (r-x), group root (r-x), others (r-x)
/lost+found permissions: owner root (rwx), group root (r-x), others (r-x)
/mnt permissions: owner root (rwx), group root (r-x), others (r-x)
/sys permissions: owner root (rwx), group root (r-x), others (r-x)
After restoration, reboot; the system will be identical to the backup state.
Imaging (backup to a new host)
1. Verify the source system version and install the same version on the target machine with identical partition layout.
lsb_release -a
uname -a
df -Th
free -h2. Create backup on the source.
# Exclude /dev and /tmp due to hardware differences; add any other exclusions as needed
# Save to /mnt where there is enough space
cd /
tar cvpzf /mnt/system_backup.tar.gz / --exclude=/mnt/system_backup.tar.gz \
--exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys \
--exclude=/dev --exclude=/tmp --exclude=/media
# Upload to target host
scp /mnt/system_backup.tar.gz [email protected]:/mnt3. On the target, boot from ISO/LiveCD, mount the target disk (usually under /media), and restore.
sudo -s
cd /media/<target-uuid>
# Backup important config files
# Remove existing system directories except the excluded ones
rm -rf root home usr lib lib64 etc var bin sbin opt boot run selinux vmlinuz initrd.img
# Restore backup
mount /dev/vda1 /mnt/1
tar xvpfz system_backup.tar.gz -C /mnt/1
chroot ./
# Edit /etc/fstab and /boot/grub/grub.cfg to match the new UUIDs
# Adjust network and service configurations as neededAfter completing these steps, exit the chroot, unmount, and reboot. If GRUB reports errors (e.g., "boot error 15" or "dracut: don't know how to handle root=..."), adjust the GRUB configuration or kernel parameters accordingly.
rsync command
Use rsync for file‑level backups, ensuring the destination partition is formatted with a compatible filesystem (NTFS, FAT, EXT, etc.) to avoid size limitations.
# Backup
rsync -Pa / /media/usb/backup_20170410 --exclude=/media/* --exclude=/sys/* --exclude=/proc/* --exclude=/mnt/* --exclude=/tmp/*
# Restore
rsync -Pa /media/usb/backup_20170410 /dd command
dd performs sector‑by‑sector cloning; the target partition must be at least as large as the source and the process can be slow.
# Backup
df -h # check source partition
dd if=/dev/sda1 of=/dev/sdb3 # clone sda1 to sdb3
# Restore
dd if=/dev/sdb3 of=/dev/sda1 # restore sdb3 to sda1Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
