Ubuntu可以將系統(tǒng)備份為一個tar壓縮文件,也能很方便地從該文件恢復系統(tǒng)旭咽。
備份
我們的目標是備份/目錄,但是不備份/home, 以及/proc, /sys, /mnt, /media, /run, /dev
要實現(xiàn)這一點,執(zhí)行下列命令
cd /
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
其中
--exclude=/example/path: 不需要備份的文件或目錄的路徑
--one-file-system: 該命令能自動exclude /home, 以及/proc, /sys, /mnt, /media, /run, /dev.
/: 需要backup的partition
恢復
進入livecd灿里,用gparted工具對硬盤進行分區(qū)和格式化
然后mount你想恢復的分區(qū)
一般會掛載在/mnt下
然后用下述命令恢復
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).
修復grub
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