使用PBS备份PVE物理机特定路径
This post shows you how to use PBS (Proxmox Backup Server) to backup a specific directory (or mount point) of a PVE (Proxmox Virtual Environment) server, which is NOT exactly same thing in my mind – to backup a physical PVE machine and restore to be another new one (with all my personal settings in) though, but still somehow interesting and worth a try.
本文简介如何使用PBS(Proxmox Backup Server)进行PVE物理机备份。
本以为,这功能可以把pve物理机clone一份然后秒恢复成一台新物理机(类似硬盘dd但更简单)。但实际并非如此,该功能是把特定路径(比如根目录)下的文件整体打包备份(不含已挂载别的分区的路径);而恢复时也不是整分区恢复,而是按文件恢复,且文件已经存在时会报错。
虽然跟想的不太一样,至少这货有一点好处,简便易操作。相当于给PVE物理机磁盘打了个snapshot,而且PBS的管理界面可以把备份解开,只下载(恢复)其中某一个文件,有一定的实用价值。
现在看下备份过程,在PVE物理机上执行如下命令 –
1 2 3 4 5 6 7 8 9 10 11 12 |
root@pve-test-pbs:~# proxmox-backup-client backup 121-root.pxar:/ --repository 192.168.1.122:test-store-01 Starting backup: host/pve-test-pbs/2020-10-13T03:06:41Z Client name: pve-test-pbs Starting backup protocol: Tue Oct 13 11:06:41 2020 Upload directory '/' to '192.168.1.122:test-store-01' as 121-root.pxar.didx 121-root.pxar: had to upload 1.67 GiB of 1.87 GiB in 23.20s, average speed 73.54 MiB/s). 121-root.pxar: backup was done incrementally, reused 208.00 MiB (10.9%) Uploaded backup catalog (1.00 MiB) Duration: 23.28s End Time: Tue Oct 13 11:07:04 2020 root@pve-test-pbs:~# |
其中 –
- backup指备份操作。
- 121-root.pxar是备份到具体的文件名,而pxar是pbs使用的备份文件格式。上一篇PBS初体验中提到了PBS中特殊的存储方式,这里也不例外,121-root.pxar文件名在pbs中也只是个索引文件,具体数据存储也是打散在.chunks下的65536个子目录中。
- :/ 指要备份root挂载点(之下比如/var挂载了别的分区,则不会被备份到)。
- --repository 告诉备份命令,要备份到远端的PBS服务器。
- 192.168.1.122:test-store-01 给出PBS服务器的具体IP(端口默认8007)和存储池名字。
备份完成后,从PBS管理界面,可以看到备份信息。
更有意思的是,备份可以展开,甚至可以下载某一具体文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# root @ pbs-test in /mnt/datastore/test-store-01 [11:29:24] $ ll total 24K drwxr-xr-x 4 backup backup 4.0K Oct 13 11:06 host drwx------ 2 root root 16K Oct 12 15:29 lost+found drwxr-xr-x 3 backup backup 4.0K Oct 12 16:02 vm # root @ pbs-test in /mnt/datastore/test-store-01 [11:29:36] $ ll host/pve-test-pbs/2020-10-13T03:06:41Z total 40K -rw-r--r-- 1 backup backup 25K Oct 13 11:07 121-root.pxar.didx -rw-r--r-- 1 backup backup 4.2K Oct 13 11:07 catalog.pcat1.didx -rw-r--r-- 1 backup backup 399 Oct 13 11:07 index.json.blob |
那么如果从PVE上列出PBS的备份,从而检查内容和恢复呢?
如下列出目标PBS上一共两台host和一台vm共4个备份文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@pve-test-pbs:~# proxmox-backup-client snapshots --repository 192.168.1.122:test-store-01 +========================================+=============+========================================================+ | snapshot | size | files | +========================================+=============+========================================================+ | host/aqui-vm-host/2020-10-13T02:00:57Z | 3119187277 | 143-root.pxar catalog.pcat1 index.json | +----------------------------------------+-------------+--------------------------------------------------------+ | host/pve-test-pbs/2020-10-13T03:06:41Z | 2008406535 | 121-root.pxar catalog.pcat1 index.json | +----------------------------------------+-------------+--------------------------------------------------------+ | vm/503/2020-10-12T08:00:41Z | 68719477444 | client.log drive-scsi0.img index.json qemu-server.conf | +----------------------------------------+-------------+--------------------------------------------------------+ | vm/503/2020-10-12T09:15:02Z | 68719477442 | client.log drive-scsi0.img index.json qemu-server.conf | +========================================+=============+========================================================+ root@pve-test-pbs:~# |
检查第二个备份中index.json的内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
root@pve-test-pbs:~# proxmox-backup-client restore host/pve-test-pbs/2020-10-13T03:06:41Z --repository 192.168.1.122:test-store-01 index.json - { "backup-id": "pve-test-pbs", "backup-time": 1602558401, "backup-type": "host", "files": [ { "crypt-mode": "none", "csum": "0bad410a155ff19d8293ca32664b0e650cf30ccd9c526f70308ab99c534b3560", "filename": "121-root.pxar.didx", "size": 2007354489 }, { "crypt-mode": "none", "csum": "0d8e3b159d2b31f97cf25a0ff0ed447fbc80b3e1684a58843f9b2aa13defd6ae", "filename": "catalog.pcat1.didx", "size": 1051647 } ], "signature": null, "unprotected": { "chunk_upload_stats": { "compressed_size": 678587355, "count": 506, "duplicates": 65, "size": 1790302653 } } } root@pve-test-pbs:~# |
你还可以灰常方便的把远端备份挂载到本地的目录下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
root@pve-test-pbs:~# mkdir /mnt/backup root@pve-test-pbs:~# proxmox-backup-client mount host/pve-test-pbs/2020-10-13T03:06:41Z --repository 192.168.1.122:test-store-01 121-root.pxar /mnt/backup FUSE library version: 3.4.1 root@pve-test-pbs:~# root@pve-test-pbs:~# cd /mnt/backup/ root@pve-test-pbs:/mnt/backup# ls -l total 0 lrwxrwxrwx 1 root root 0 Mar 6 2020 bin -> usr/bin drwxr-xr-x 2 root root 0 Oct 13 10:26 boot drwxr-xr-x 2 root root 0 Oct 13 10:36 dev drwxr-xr-x 2 root root 0 Oct 13 10:33 etc drwxr-xr-x 2 root root 0 Feb 2 2020 home lrwxrwxrwx 1 root root 0 Mar 6 2020 lib -> usr/lib lrwxrwxrwx 1 root root 0 Mar 6 2020 lib32 -> usr/lib32 lrwxrwxrwx 1 root root 0 Mar 6 2020 lib64 -> usr/lib64 lrwxrwxrwx 1 root root 0 Mar 6 2020 libx32 -> usr/libx32 drwx------ 2 root root 0 Oct 13 10:22 lost+found drwxr-xr-x 2 root root 0 Mar 6 2020 media drwxr-xr-x 2 root root 0 Mar 6 2020 mnt drwxr-xr-x 2 root root 0 Mar 6 2020 opt dr-xr-xr-x 2 root root 0 Oct 13 10:27 proc drwx------ 2 root root 0 Oct 13 10:33 root drwxr-xr-x 2 root root 0 Oct 13 10:29 run lrwxrwxrwx 1 root root 0 Mar 6 2020 sbin -> usr/sbin drwxr-xr-x 2 root root 0 Mar 6 2020 srv dr-xr-xr-x 2 root root 0 Oct 13 10:27 sys drwxrwxrwt 2 root root 0 Oct 13 10:33 tmp drwxr-xr-x 2 root root 0 Mar 6 2020 usr drwxr-xr-x 2 root root 0 Mar 6 2020 var root@pve-test-pbs:/mnt/backup# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=1990424k,nr_inodes=497606,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=403004k,mode=755) /dev/mapper/pve-root on / type ext4 (rw,relatime,errors=remount-ro) # 部分省略 tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=403000k,mode=700) /dev/fuse on /mnt/backup type fuse (ro,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions) root@pve-test-pbs:/mnt/backup# |
但当你要恢复的时候
1 2 |
root@pve-test-pbs:/mnt/backup# proxmox-backup-client restore host/aqui-vm-host/2020-10-13T02:00:57Z --repository 192.168.1.122:test-store-01 143-root.pxar / Error: error extracting archive - error at entry "bin": EEXIST: File exists |
没法怪PBS,对活着的系统做根分区恢复,类似给飞行中的飞机换引擎,未免有点强人所难。
如果不是根分区,抑或恢复到别的分区,应该是完全OK的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
root@pve-test-pbs:~# proxmox-backup-client restore host/pve-test-pbs/2020-10-13T03:06:41Z --repository 192.168.1.122:test-store-01 121-root.pxar /mnt/test root@pve-test-pbs:~# ls -l /mnt/test/ total 64 lrwxrwxrwx 1 root root 7 Mar 6 2020 bin -> usr/bin drwxr-xr-x 5 root root 4096 Oct 13 10:26 boot drwxr-xr-x 2 root root 4096 Oct 13 10:36 dev drwxr-xr-x 88 root root 4096 Oct 13 10:33 etc drwxr-xr-x 2 root root 4096 Feb 2 2020 home lrwxrwxrwx 1 root root 7 Mar 6 2020 lib -> usr/lib lrwxrwxrwx 1 root root 9 Mar 6 2020 lib32 -> usr/lib32 lrwxrwxrwx 1 root root 9 Mar 6 2020 lib64 -> usr/lib64 lrwxrwxrwx 1 root root 10 Mar 6 2020 libx32 -> usr/libx32 drwx------ 2 root root 4096 Oct 13 10:22 lost+found drwxr-xr-x 2 root root 4096 Mar 6 2020 media drwxr-xr-x 3 root root 4096 Mar 6 2020 mnt drwxr-xr-x 2 root root 4096 Mar 6 2020 opt dr-xr-xr-x 2 root root 4096 Oct 13 10:27 proc drwx------ 6 root root 4096 Oct 13 10:33 root drwxr-xr-x 2 root root 4096 Oct 13 10:29 run lrwxrwxrwx 1 root root 8 Mar 6 2020 sbin -> usr/sbin drwxr-xr-x 2 root root 4096 Mar 6 2020 srv dr-xr-xr-x 2 root root 4096 Oct 13 10:27 sys drwxrwxrwt 8 root root 4096 Oct 13 10:33 tmp drwxr-xr-x 13 root root 4096 Mar 6 2020 usr drwxr-xr-x 11 root root 4096 Mar 6 2020 var root@pve-test-pbs:~# df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 394M 5.7M 388M 2% /run /dev/mapper/pve-root 16G 2.0G 13G 14% / tmpfs 2.0G 25M 1.9G 2% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/fuse 30M 16K 30M 1% /etc/pve tmpfs 394M 4.0K 394M 1% /run/user/0 /dev/sdb1 63G 2.1G 58G 4% /mnt/test |
可以看到恢复完成后没有返回任何提示信息,但列举目标目录的内容,以及容量变化,应该是完整恢复好了。
这次实验也花了2小时左右,更多深入测试就不做了,有需要的同学可以进一步读下官网文档。
文章的脚注信息由WordPress的wp-posturl插件自动生成