Linux 如何备份整个系统并恢复

大家见过Windows系统备份恢复所有环境的教程。MacOS有时间机器。Linux下做到整个备份恢复并保留全部环境设置的教程不多。今天刚好测试了下。并记录下来以供大家参考。

缘由是我在一个虚拟机做了很多环境设置,但是不小心把磁盘搞的太大(实际占用空间不多,但是无论怎么压缩也减少不了体积。),备份起来不方便。不多说看下面。

先看下我的目录结构

sda   (旧磁盘)          8:0  0 256G 0 disk

├─sda1           8:1  0  99M 0 part /boot/efi

├─sda2           8:2  0 216M 0 part

└─sda3           8:3  0  40G 0 part /

sdb    (新磁盘)         8:0  0 1024G 0 disk

├─sdb1           8:1  0  99M 0 part

├─sdb2           8:2  0 128M 0 part 

├─sdb3           8:2  0 873G 0 part 

└─sdb4           8:3  0 150G 0 part 

1,虚拟机采用了LVM动态卷(方便增加容量,其实他也可以缩小容量,但我的不行。)没有采用这个技术,方法的就更方便了。先准备一个外接的磁盘(只要是容量大于整个系统占用的容量即可),然后备份所有文件,命令如下(默认都是root权限):

tar -cvpzf /media/D/backup.tar.gz –exclude=/media –one-file-system /

c:创建压缩包

v:输出压缩信息

p:保持文件原有的权限和属性

z:压缩文件为 .gz

f:指定文件名

–exclude=/example/path:不压缩指定路径下面的文件(所以你挂载的路径要排除,不然死循环了)

-one-file-system:不备份其他文件系统中的文件(只备份和系统根分区一样分区类型的文件。

如果你在备份的时候看到 /proc /dev /sys 这些目录有错误,不要惊慌。这些目录本身不是实体,无法备份。

2,备份好压缩包后。在新磁盘创建同样的分区大小和格式。如果是换到新机器的话,你还要准备一个 Live CD 镜像,从镜像启动。类似 WinPE。启动好系统后,进行如下命令:

挂载新磁盘 mount /dev/sdb3(你的磁盘位置,不清楚用 df -h 查看) /media/D

转到目录 cd /media/D/

解压备份
tar -xvpzf /path/to/backup.tar.gz -C /media/D/ --numeric-owner

用 LS 命令查看文件是否缺失 ,如果没有以下目录,自行用 mkdir 补全

proc sys mnt media tmp dev run

当然我说的是我的。你可以在备份的时候记录下原来的目录有哪些。

3,创建虚拟环境 chroot /media/D/

创建引导 grub-install –recheck –no-floppy /dev/sdb1(这个目录看你具体情况)

修改 fstab 文件

echo "`blkid | grep sdb1 | awk '{printf $2}' | sed 's/"//g'` / ext4 defaults 0 1" >> /etc/fstab

这里注意下,你可以对照下原来的 fstab 文件。做对应修改。应该变的只有 UUID 名和路径。

再次查看下 vi /etc/fstab 。看是否正确,WQ保存。

升级引导 update-grub

exit 这个命令很重要。不用这个命令退出,所做修改无效哦!

reboot 重启,试一试看吧。我相信很多可能会失败。

要么卡在 grub 或者 initramfs。

这个只是大致的教程,具体实操要靠自己。

卡在 grub 的话 可以试一试简单的方法如下:

启动到 live cd,执行如下

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update

sudo apt-get install -y boot-repair && boot-repair

按提示修复 grub 引导

initramfs 的话,root 目录设置错了。

Pantum Printer ALL Series PDF 奔图打印机全系列维修手册

用奔图打印机的人辛苦了。这么垃圾的打印机你们还在用,哈哈哈!

奔图Pantum P3100-3200、P3400系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996692773-4e4b49?p=9280 (访问密码: 9280)

Pantum P1000-2000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700534-3d9cc9?p=9280 (访问密码: 9280)

Pantum M6550、M6600系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700522-d7a253?p=9280 (访问密码: 9280)

Pantum M6200-6500系列维修手册 V1.2.pdf: https://url64.ctfile.com/f/22136564-996700501-2ff87a?p=9280 (访问密码: 9280)

Pantum M5000-6000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700492-c3f8ca?p=9280 (访问密码: 9280)

PantumM6700-6800 M7100-7200系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700486-fb7576?p=9280 (访问密码: 9280)

Pantum P5500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700477-77f705?p=9280 (访问密码: 9280)

Pantum P5000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700474-367866?p=9280 (访问密码: 9280)

Pantum P4000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700462-38f961?p=9280 (访问密码: 9280)

Pantum P3500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700444-398dfd?p=9280 (访问密码: 9280)

Pantum P3010-3060、3300系列维修手册1.1.pdf: https://url64.ctfile.com/f/22136564-996700438-54078d?p=9280 (访问密码: 9280)

Pantum P3010-3060、3300系列维修手册1.0.pdf: https://url64.ctfile.com/f/22136564-996700432-d79afc?p=9280 (访问密码: 9280)

Pantum P3000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700423-0f72dd?p=9280 (访问密码: 9280)

Pantum P2200-2500系列维修手册 V1.2.pdf: https://url64.ctfile.com/f/22136564-996700417-b70546?p=9280 (访问密码: 9280)

Pantum CP2500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704950-03a8a7?p=9280 (访问密码: 9280)

Pantum CP2500 PLUS.pdf: https://url64.ctfile.com/f/22136564-996704944-7df004?p=9280 (访问密码: 9280)

Pantum CM8500维修手册.pdf: https://url64.ctfile.com/f/22136564-996704935-1329cc?p=9280 (访问密码: 9280)

Pantum CM8500维修手册.pdf: https://url64.ctfile.com/f/22136564-996704935-1329cc?p=9280 (访问密码: 9280)

Pantum CM9500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704914-6cbd6d?p=9280 (访问密码: 9280)

Pantum M9000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704899-afb5c3?p=9280 (访问密码: 9280)

Pantum CM2200系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704884-b547bf?p=9280 (访问密码: 9280)

Pantum CP2200系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704875-cd4f74?p=9280 (访问密码: 9280)

Pantum P2600系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704869-1d08b9?p=9280 (访问密码: 9280)

Pantum CP1000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704860-963510?p=9280 (访问密码: 9280)

Pantum M7650系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704857-ef1d28?p=9280 (访问密码: 9280)

Pantum P9500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704845-f90327?p=9280 (访问密码: 9280)

Pantum CP9500系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704827-0ca3a0?p=9280 (访问密码: 9280)

Pantum BM4000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704815-fe9552?p=9280 (访问密码: 9280)

Pantum BP5000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996704782-a1bb5e?p=9280 (访问密码: 9280)

Pantum M7300系列维修手册 V1.3.pdf: https://url64.ctfile.com/f/22136564-996704755-72a1f3?p=9280 (访问密码: 9280)

Pantum P1000-2000系列维修手册.pdf: https://url64.ctfile.com/f/22136564-996700534-3d9cc9?p=9280 (访问密码: 9280)