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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值