Master Linux System Backup and Restore with tar, rsync, and dd
Learn how to safely back up and restore a Linux system using tar for full archives, rsync for file synchronization, and dd for sector-level cloning, including command syntax, exclusion options, and post‑restore steps to ensure a seamless migration or disaster recovery.
tar command
Copy (local backup of the entire system, restore to the same machine)
Make sure there is enough free space in the root directory for the backup.
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 file to root directory
tar xvpfz system_backup.tar.gz -C /
or
tar xvpfj system_backup.tar.bz2 -C /
# Create excluded directories
mkdir proc
mkdir lost+found
mkdir mnt
mkdir 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: owner root, group root, read & execute for all
/sys permissions: owner root, group root, read & execute for all
After restoration and reboot, everything will be exactly as it was at backup time.
Image (backup on one machine, restore to a new host)
1, Check system version and install the same version on the target machine (minimal install). Ensure partition format and type are identical.
lsb_release -a
uname -a
df -Th
free -h
2, Backup source system
# Exclude directories that differ on the target (dev, tmp, etc.) and any additional paths you wish.
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]:/mnt
3, On the target machine, boot with ISO/LiveCD, mount the disk (usually auto‑mounted under /media).
sudo -s
cd /media/<uuid>
# Backup important config files such as /boot/gurb/gurb.cfg and /etc/fstab, note the UUIDs.
# Remove duplicate files (except the excluded ones like dev, mnt, media, sys)
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
# Do NOT extract to / directly; use the mounted directory.
tar xvpfz system_backup.tar.gz -C /mnt/1
cd /mnt/1 # you can see the root structure; edit fstab if needed
chroot ./ # now / becomes the new root for editing.
# After restore, update UUIDs in /etc/fstab and /boot/gurb/gurb.cfg to match the new system.
# Adjust network interface and IP configuration as needed.
# Disable services that depend on the original platform (e.g., NTP, monitoring agents) and remove autostart entries.
# Ubuntu: runlevel to check current level (default is 2). Remove S* scripts in /etc/rc2.d or delete corresponding files in /etc/init.d.
# CentOS: use systemctl to manage services.
# Finish
exit # leave chroot
cd ~
umount /mnt/1
# Reboot. If GRUB shows "boot error 15: file not found", check GRUB kernel files (usually /boot partition).
# If GRUB shows "dracut: don't know how to handle root=f078", change root=UUID to root=/dev/sdaX.
# If system reports /usr/libexec/gconf-sanity-check-2 exit status 256, run:
chmod 777 /tmprsync command
Ensure the target partition format is NTFS, FAT, EXT, etc., to avoid issues with files larger than 4 GB.
# Ensure another partition or external storage is mounted; check with df -lh.
# 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‑level cloning; the target partition must be larger than the source, and unused space will also be cloned, which can be slow.
# Backup
df -h # view the partition containing the system
dd if=/dev/sda1 of=/dev/sdb3 # copy 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.
