Ubuntu can back up the system as a tar compressed file, and it can also easily restore the system from this file.
Our goal is to back up / directory, but not back up /home, and /proc, /sys, /mnt, /media, /run, /dev
To achieve this, execute the following command
cd /
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
among them
--Exclude=/example/path: path of files or directories that do not need to be backed up
--One-file-system: This command can automatically exclude /home, and /proc, /sys, /mnt, /media, /run, /dev.
/: The partition that needs backup
Enter livecd, use gparted tool to partition and format the hard disk
Then mount the partition you want to recover
Usually mounted under /mnt
Then use the following command to restore
sudo mount /dev/sda2 /mnt
sudo tar -xvpzf /path/to/backup.tar.gz -C /mnt --numeric-owner
- - numeric-owner - This option tells tar to restore the numeric owners of the files in the archive, rather than matching to any user names in the environment you are restoring from. This is due to that the user id:s in the system you want to restore don't necessarily match the system you use to restore(eg a live CD).
sudo su
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
grub-install --recheck /dev/sda
update-grub
umout
exit
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/dev/pts
sudo umount /mnt/dev
sudo umount /mnt
Recommended Posts