在其他盘或者本地盘创建一个临时镜像并且格式化
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
|
➜ btrfs-snapshot-test sudo truncate -s 8G /data/btrfs-test.img
➜ btrfs-snapshot-test sudo mkfs.btrfs -L "btrfs-test" /data/btrfs-test.img
btrfs-progs v6.2
See http://btrfs.wiki.kernel.org for more information.
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)
Label: btrfs-test
UUID: e73b1682-33be-4550-a0d4-7e3958923a46
Node size: 16384
Sector size: 4096
Filesystem size: 8.00GiB
Block group profiles:
Data: single 8.00MiB
Metadata: DUP 256.00MiB
System: DUP 8.00MiB
SSD detected: no
Zoned device: no
Incompat features: extref, skinny-metadata, no-holes
Runtime features: free-space-tree
Checksum: crc32c
Number of devices: 1
Devices:
ID SIZE PATH
1 8.00GiB /data/btrfs-test.img
|
让我们挂载到同级目录,实际可能是其他目录, 现在假装这个是另一个盘的需要
备份我们hello的内容的文件夹。
1
2
|
➜ btrfs-snapshot-test sudo mount /data/btrfs-test.img i-am-backup-from-other-disk
➜ btrfs-snapshot-test sudo chown -R liuliancao:liuliancao i-am-backup-from-other-disk
|
如果尝试直接在新目录上创建子卷的快照会失败,因为根卷是同一个设备,
1
2
3
|
➜ btrfs-snapshot-test sudo btrfs subvolume snapshot lqx-btrfs-first i-am-backup-from-other-disk/lqx-btrfs-first-backup
Create a snapshot of 'lqx-btrfs-first' in 'i-am-backup-from-other-disk/lqx-btrfs-first-backup'
ERROR: cannot snapshot 'lqx-btrfs-first': Invalid cross-device link
|
这个时候需要用 btrfs-send
命令配合 btrfs-receive
, 而如果向直接send也
会失败,希望这个卷是只读的。
1
2
3
|
➜ btrfs-snapshot-test sudo btrfs send lqx-btrfs-first | sudo btrfs receive i-am-backup-from-other-disk/
ERROR: subvolume /home/liuliancao/btrfs-snapshot-test/lqx-btrfs-first is not read-only
ERROR: empty stream is not considered valid
|
这里我们把 lqx-btrfs-first
创建一个名为 hello-readonly
快照
1
2
|
➜ btrfs-snapshot-test sudo btrfs subvolume snapshot -r lqx-btrfs-first hello-readonly
Create a readonly snapshot of 'lqx-btrfs-first' in './hello-readonly'
|
我们尝试把 hello-readonly
送到 i-am-backup-from-other-disk
上面
1
2
3
4
5
|
➜ btrfs-snapshot-test sudo btrfs send hello-readonly | sudo btrfs receive i-am-backup-from-other-disk/
At subvol hello-readonly
At subvol hello-readonly
➜ btrfs-snapshot-test ls i-am-backup-from-other-disk/
hello-readonly
|
如果你没有一个 btrfs
系统,那么怎么做呢,你可以send到一个固定的文件里
面,通过这个文件你相当于把子卷保存在了其他文件系统的目录里面
1
2
3
4
5
6
7
8
|
➜ btrfs-snapshot-test sudo btrfs send -f lqx-btrfs-first-all.btrfs lqx-btrfs-first
ERROR: subvolume /home/liuliancao/btrfs-snapshot-test/lqx-btrfs-first is not read-only
➜ btrfs-snapshot-test sudo btrfs send -f /data/lqx-btrfs-first-all.btrfs hello-readonly
At subvol hello-readonly
➜ btrfs-snapshot-test ls /data/lqx-btrfs-first-all.btrfs
/data/lqx-btrfs-first-all.btrfs
➜ btrfs-snapshot-test ls -lh /data/lqx-btrfs-first-all.btrfs
-rw------- 1 root root 936 10月17日 09:47 /data/lqx-btrfs-first-all.btrfs
|