一个简单的示例,用于进行 RBD 复制。
基于 scuttlemonkey 的这篇帖子:https://ceph.net.cn/dev-notes/incremental-snapshots-with-rbd/, 这里有一个示例脚本,用于将 rbd 镜像同步到远程集群(例如用于备份)。在下面的示例中,同步到同一集群上的“archive”池。 (对于远程主机,您需要使用 ssh 密钥。)
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
| #!/bin/bash
pool='rbd'
pooldest='archive'
rbd="myrbd"
destination_host="127.0.0.1"
snapname='rbd-sync-'
# Retreive last synced id
expr=" $snapname\([[:digit:]]\+\)"
if rbd info $pool/$rbd >/dev/null 2>&1; then
rbd snap ls $pool/$rbd | grep "$expr" | sed "s/.*$expr.*/\1/g" | sort -n > /tmp/rbd-sync-snaplistlocal
else
echo "no image $pool/$rbd"
return
fi
if ssh $destination_host rbd info $pooldest/$rbd >/dev/null 2>&1; then
ssh $destination_host rbd snap ls $pooldest/$rbd | grep "$expr" | sed "s/.*$expr.*/\1/g" | sort -n > /tmp/rbd-sync-snaplistremote
else
echo "" > /tmp/rbd-sync-snaplistremote
fi
syncid=$(comm -12 /tmp/rbd-sync-snaplistlocal /tmp/rbd-sync-snaplistremote | tail -n1)
lastid=$(cat /tmp/rbd-sync-snaplistlocal /tmp/rbd-sync-snaplistremote | sort -n | tail -n1)
nextid=$(($lastid + 1))
# Initial sync
if [ "$syncid" = "" ]; then
echo "Initial sync with id $nextid"
rbd snap create $pool/$rbd@$snapname$nextid
rbd export --no-progress $pool/$rbd@$snapname$nextid - \
| ssh $destination_host rbd import --image-format 2 - $pooldest/$rbd
ssh $destination_host rbd snap create $pooldest/$rbd@$snapname$nextid
# Incremental sync
else
echo "Found synced id : $syncid"
rbd snap create $pool/$rbd@$snapname$nextid
echo "Sync $syncid -> $nextid"
rbd export-diff --no-progress --from-snap $snapname$syncid $pool/$rbd@$snapname$nextid - \
| ssh $destination_host rbd import-diff - $pooldest/$rbd
fi
|
另一个示例:https://www.rapide.nl/blog/item/ceph_-_rbd_replication