Operations 8 min read

Master Linux System Backup and Restore with tar, rsync, and dd

This guide explains how to back up an entire Linux system or create a disk image using tar, rsync, and dd commands, covering exclusion of system directories, restoration steps, and special considerations for migrating to a new host.

ITPUB
ITPUB
ITPUB
Master Linux System Backup and Restore with tar, rsync, and dd

Using tar for full system backup and restore

Before creating a backup, ensure the root filesystem has enough free space. The following commands create compressed archives while excluding volatile directories such as /proc, /lost+found, /mnt, and /sys.

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 the system
cd /
# upload the archive to the root directory first
# For tar.gz
tar xvpfz system_backup.tar.gz -C /
# For tar.bz2
tar xvpfj system_backup.tar.bz2 -C /

# Create placeholder directories to match the excluded paths
mkdir proc lost+found mnt sys

/proc permissions: owner root, group root – read & execute for all.

/lost+found permissions: owner root, group root – read, write & execute for owner; read & execute for group and others.

/mnt permissions: same as /proc.

/sys permissions: same as /proc.

After restoration, reboot the machine; the system will behave exactly as it did at the time of backup.

Creating a disk image for migration to a new host

1. Verify the source system version and install the same version on the target machine (minimal installation is sufficient). Ensure partition layout and filesystem types match.

lsb_release -a
uname -a
df -Th
free -h

2. Back up the source system, excluding directories that differ between machines (e.g., /dev, /tmp) and any additional paths you choose.

cd /
# Store the archive on 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 the archive to the target host
scp /mnt/system_backup.tar.gz [email protected]:/mnt

3. On the target machine, boot from an ISO/LiveCD, mount the destination disk (usually under /media), and prepare for restoration.

sudo -s
cd /media/<em>uuid_of_target_partition</em>
# Record important configuration files (e.g., /boot/grub/grub.cfg, /etc/fstab) and their UUIDs.
# Remove all directories except those deliberately excluded during backup.
rm -rf root home usr lib lib64 etc var bin sbin opt boot run selinux vmlinuz initrd.img

# Restore the backup
mount /dev/vda1 /mnt/1
# Extract the archive into the mounted filesystem
tar xvpfz system_backup.tar.gz -C /mnt/1

# Chroot into the restored system to edit configuration files
chroot ./
# Update /etc/fstab and boot loader configuration with the correct UUIDs.
# Adjust network settings, disable services that depend on the original hardware, etc.
exit
umount /mnt/1
reboot

If GRUB reports errors such as "boot error 15" or "dracut: don't know how to handle root=...", adjust the root= parameter in the boot configuration to point to the correct device (e.g., root=/dev/sdaX) or ensure the /boot partition is correctly referenced.

Using rsync for file‑level backup

rsync is suitable for incremental backups and works well with partitions formatted as NTFS, FAT, EXT, etc., avoiding the 4 GB file size limitation of some filesystems.

# Backup (exclude media, sys, proc, mnt, tmp directories)
rsync -Pa / /media/usb/backup_20170410 \
    --exclude=/media/* \
    --exclude=/sys/* \
    --exclude=/proc/* \
    --exclude=/mnt/* \
    --exclude=/tmp/*

# Restore
rsync -Pa /media/usb/backup_20170410 /

Using dd for sector‑level cloning

dd creates a raw copy of a partition; the target partition must be at least as large as the source. This method copies unused space as well and can be slower than file‑level tools.

# Backup
df -h   # identify source partition (e.g., /dev/sda1)
dd if=/dev/sda1 of=/dev/sdb3   # copy sda1 to sdb3

# Restore
dd if=/dev/sdb3 of=/dev/sda1   # copy back to original partition
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxBackupSystem Administrationrsyncddtar
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.