Master Linux System Backup & Recovery: Tar, Rsync, DD & Imaging Guide
This guide explains how to safely back up and restore a Linux system using tar archives, rsync synchronization, dd cloning, and full-disk imaging, covering command syntax, exclusion of volatile directories, preparation steps, and post‑restore configuration to ensure a reliable recovery.
Deleting a database and running away is a joke, but in real work you must back up; otherwise the database is gone and you can't run.
tar command
Backup the whole system on the same machine, restore to the same machine.
Ensure sufficient 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 directories to be excluded when backing up
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: same as above.
/sys permissions: same as above.
After restoration and reboot, everything will be exactly as it was at backup time.
Image (backup system to a new host)
1. Check system version and install the same version on the target machine (minimal installation), ensuring partition layout and type match.
lsb_release -a
uname -a
df -Th
free -h2. Backup source system.
# Because the target and source hardware differ, exclude /dev and /tmp; add other exclusions as needed.
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. Boot the target machine with ISO/LiveCD, mount disks (usually under /media).
sudo -s
cd /media/<uuid>
# backup important config files /boot/grub/grub.cfg /etc/fstab
# record UUIDs
# delete duplicate files, keep only necessary directories
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
cd /mnt/1
chroot ./After restoration, edit /etc/fstab to replace UUIDs with those of the new partitions, and adjust /boot/grub/grub.cfg accordingly. Modify network and other configuration files as needed.
If services depend on the original platform (e.g., NTP, monitoring agents), disable them and prevent auto‑start.
Ubuntu: check the current runlevel with runlevel (default is 2). Services starting with “S” in /etc/rc2.d are auto‑started; remove unwanted symlinks or scripts in /etc/init.d.
vim /etc/init.d/rc.local
# CentOS: use systemctlFinish with:
exit # leave chroot
cd ~
umount /mnt/1
# reboot; system should start normally.
# If GRUB shows “boot error 15: file not found”, check kernel location in GRUB config (usually related to /boot partition).
# If GRUB shows “dracut: don't know how to handle root=...”, change root=UUID to root=/dev/sdaX format.
# If system reports /usr/libexec/gconf-sanity-check-2 exit status 256, run: chmod 777 /tmprsync command
Prefer a partition formatted as NTFS, FAT, EXT, etc., to avoid issues with files larger than 4 GB.
# 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 at least as large as the source and the process can be slow.
# backup
df -h # view partition sizes
dd if=/dev/sda1 of=/dev/sdb3 # copy sda1 to sdb3
# restore
dd if=/dev/sdb3 of=/dev/sda1 # copy backSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
