Proxmox VE

proxmox ve ZFS快照、备份、恢复2019-04-16

2019-04-16  本文已影响0人  龙天ivan

创建zpool池

root@pve:~# zpool create test /dev/sda6

这时/dev/sda6最好不要用这种sdx的方式,容易发生变化造成找不到硬盘,建议ls -al /dev/disk/by-id 看一下对应的id,然后通过zpool create test /dev/disk/by-id/xxxxxxx的方式创建

查看

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        336K  95.9G    96K  /test

查看zpool

root@pve:~# zpool status test
  pool: test
 state: ONLINE
  scan: none requested
config:

    NAME        STATE     READ WRITE CKSUM
    test        ONLINE       0     0     0
      sda6      ONLINE       0     0     0

errors: No known data errors

创建zfs

root@pve:~# zfs create test/home

查看

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        432K  95.9G    96K  /test
test/home                    96K  95.9G    96K  /test/home

创建一个snap1.txt文件用于测试

root@pve:~# touch /test/home/snap1.txt

root@pve:~# ls /test/home/
snap1.txt

创建一个快照名叫snap1

root@pve:~# zfs snapshot test@snap1 -r

查看

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        440K  95.9G    96K  /test
test@snap1                    0B      -    96K  -
test/home                   104K  95.9G   104K  /test/home
test/home@snap1               0B      -   104K  -

创建一个新文件snap2.txt用于测试

root@pve:~# touch /test/home/snap2.txt

再创建一个快照取名snap2

root@pve:~# zfs snapshot test/home@snap2

查看

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        644K  95.9G    96K  /test
test@snap1                   56K      -    96K  -
test/home                   168K  95.9G   104K  /test/home
test/home@snap1              64K      -   104K  -
test/home@snap2               0B      -   104K  -

把快照进行远程备份,这里/mnt/pve/omv-cifs是挂载的omv上的samba共享文件夹,快照保存为test.snap1

root@pve:~# zfs send -Rv test@snap1 > /mnt/pve/omv-cifs/test.snap1
skipping snapshot test/home@snap2 because it was created after the destination snapshot (snap1)
full send of test@snap1 estimated size is 40.6K
full send of test/home@snap1 estimated size is 44.6K
total estimated size is 85.2K
TIME        SENT   SNAPSHOT
TIME        SENT   SNAPSHOT

同样把snap2也备份一下

root@pve:~# zfs send -Rv test/home@snap2 > /mnt/pve/omv-cifs/test.home.snap2
full send of test/home@snap1 estimated size is 44.6K
send from @snap1 to test/home@snap2 estimated size is 30.6K
total estimated size is 75.2K
TIME        SENT   SNAPSHOT
TIME        SENT   SNAPSHOT

下面回滚恢复一下snap1快照

root@pve:~# zfs rollback test/home@snap1 -r

下面我们会看到目录下恢复为第一个文件了,也就是第二个文件被回滚了

root@pve:~# ls /test/home/
snap1.txt

再查看一下zfs,发现snap2的快照也没了

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        648K  95.9G    96K  /test
test@snap1                   56K      -    96K  -
test/home                   160K  95.9G   104K  /test/home
test/home@snap1              56K      -   104K  -

那我们刚才把snap2远程备份了,那试试恢复回来:

root@pve:~# cat /mnt/pve/omv-cifs/test.home.snap2 | zfs recv -Fd test

看一下zfs发现确实恢复了

root@pve:~# zfs list
NAME                        USED  AVAIL  REFER  MOUNTPOINT
test                        700K  95.9G    96K  /test
test@snap1                   64K      -    96K  -
test/home                   168K  95.9G   104K  /test/home
test/home@snap1              64K      -   104K  -
test/home@snap2               0B      -   104K  -

查看一下文件,snap2.txt也回来了

root@pve:~# ls /test/home/
snap1.txt  snap2.txt

zfs增量备份

root@pve:/# zfs list -r test
NAME              USED  AVAIL  REFER  MOUNTPOINT
test             1.10M  95.9G    96K  /test
test@snap1         56K      -    96K  -
test@snap2          0B      -    96K  -
test/home         168K  95.9G   104K  /test/home
test/home@snap1    64K      -   104K  -
test/home@snap2     0B      -   104K  -

test/home@snap2增量发送备份

root@pve:/# zfs send -vPR -I test@snap1 test@snap2 > /mnt/pve/omv-cifs/test.snap2

回滚到snap1

root@pve:/# zfs rollback -rf test@snap1
root@pve:/# zfs rollback -rf test/home@snap1
root@pve:/# zfs list -r test
NAME              USED  AVAIL  REFER  MOUNTPOINT
test             1004K  95.9G    96K  /test
test@snap1          0B      -    96K  -
test/home         104K  95.9G   104K  /test/home
test/home@snap1     0B      -   104K  -

从增量备份的snap2恢复

root@pve:/# cat /mnt/pve/omv-cifs/test.snap2 | zfs recv -Fd test
root@pve:/# zfs list -r test
NAME              USED  AVAIL  REFER  MOUNTPOINT
test             1.13M  95.9G    96K  /test
test@snap1         56K      -    96K  -
test@snap2          0B      -    96K  -
test/home         168K  95.9G   104K  /test/home
test/home@snap1    64K      -   104K  -
test/home@snap2     0B      -   104K  -
上一篇下一篇

猜你喜欢

热点阅读