Ubuntu 备份与恢复

详细教程

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


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容