Ubuntu可以将系统备份为一个tar压缩文件,也能很方便地从该文件恢复系统。
备份
我们的目标是备份/目录,但是不备份/home, 以及/proc, /sys, /mnt, /media, /run, /dev
要实现这一点,执行下列命令
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工具对硬盘进行分区和格式化
然后mount你想恢复的分区
一般会挂载在/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
网友评论