How to Backup and Restore Linux Systems Using tar, rsync, and dd
This guide explains step‑by‑step how to create full system backups and restore them on the same or a new machine using tar (both .tar.gz and .tar.bz2), rsync, and dd, including exclusion patterns, partition handling, and common post‑restore fixes.
This article provides practical instructions for backing up an entire Linux system and restoring it later, covering three primary tools: tar , rsync , and dd .
Backup and restore with tar
Full system backup (copy mode) – ensure sufficient free space on the root filesystem before starting.
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=/sysTo restore, upload the archive to the target root directory and extract:
# Restore .tar.gz
tar xvpfz system_backup.tar.gz -C /
# Restore .tar.bz2
tar xvpfj system_backup.tar.bz2 -C /Before creating the backup, create empty directories for the excluded paths so tar does not fail:
mkdir proc
mkdir lost+found
mkdir mnt
mkdir sysFile permission notes for the excluded directories are listed, e.g., /proc and /sys are readable/executable by all users.
Image backup for migration to a new host
1. Verify the source system version and hardware details ( lsb_release -a, uname -a, df -Th, free -h) and ensure the target machine uses the same OS version and partition layout.
2. Create a backup while excluding directories that differ between machines (e.g., /dev, /tmp, /media).
cd /
# Save to a separate partition with enough space
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
# Transfer to the target host
scp /mnt/system_backup.tar.gz [email protected]:/mnt3. Boot the target machine with a live ISO, mount its filesystem (usually under /media), and prepare for restoration:
sudo -s
cd /media/<em>uuid</em>
# Record important configuration files (e.g., /boot/grub/grub.cfg, /etc/fstab) and UUIDs.
# 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.img4. Restore the backup into a temporary mount point and chroot into it to edit configuration files:
mount /dev/vda1 /mnt/1
tar xvpfz system_backup.tar.gz -C /mnt/1
cd /mnt/1
chroot ./
# Edit /etc/fstab and /boot/grub/grub.cfg to replace old UUIDs with the new ones.5. Disable services that depend on the original hardware (e.g., NTP, monitoring agents). On Ubuntu, check runlevel with runlevel and edit /etc/rc2.d; on CentOS use systemctl.
6. Exit chroot, unmount, and reboot. The system should start with the same accounts and settings as the source. Troubleshooting tips for common GRUB errors and permission issues are provided.
Backup with rsync
Rsync is useful when the target partition uses a compatible filesystem (NTFS, FAT, EXT, etc.) and avoids the 4 GB file size limit of some tools.
# Backup
rsync -Pa / /media/usb/backup_20170410 \
--exclude=/media/* --exclude=/sys/* --exclude=/proc/* \
--exclude=/mnt/* --exclude=/tmp/*
# Restore
rsync -Pa /media/usb/backup_20170410 /Sector‑level cloning with dd
dd copies raw disk sectors, so the destination partition must be at least as large as the source. It is slower but creates an exact clone.
# Backup (example: clone /dev/sda1 to /dev/sdb3)
dd if=/dev/sda1 of=/dev/sdb3
# Restore
dd if=/dev/sdb3 of=/dev/sda1Use df -h to identify the source partition before running dd.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
