Samba Shadow_copy 和 Ceph RBD

laurentbarbe

我添加了一个脚本,用于为 samba shadow_copy2 与 rbd 一起使用而创建快照。有关更多详细信息,请访问 https://github.com/ksperis/autosnap-rbd-shadow-copy

如何使用:

在开始之前,您需要运行 ceph 集群并安装 samba。

验证对 ceph 集群的管理员访问权限:(不应返回错误)

1
$ rbd ls

获取脚本

1
2
3
4
5
$ mkdir -p /etc/ceph/scripts/
$ cd /etc/ceph/scripts/
$ wget https://raw.github.com/ksperis/autosnap-rbd-shadow-copy/master/autosnap.conf
$ wget https://raw.github.com/ksperis/autosnap-rbd-shadow-copy/master/autosnap.sh
$ chmod +x autosnap.sh

创建一个块设备

1
2
3
4
5
$ rbd create myshare --size=1024
$ echo "myshare" >> /etc/ceph/rbdmap
$ /etc/init.d/rbdmap reload
[ ok ] Starting RBD Mapping: rbd/myshare.
[ ok ] Mounting all filesystems...done.

格式化块设备

1
2
3
4
5
6
7
8
9
10
11
$ mkfs.xfs /dev/rbd/rbd/myshare
log stripe unit (4194304 bytes) is too large (maximum is 256KiB)
log stripe unit adjusted to 32KiB
meta-data=/dev/rbd/rbd/myshare   isize=256    agcount=9, agsize=31744 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=1024   swidth=1024 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载共享

1
2
3
$ mkdir /myshare
$ echo "/dev/rbd/rbd/myshare /myshare xfs defaults 0 0" >> /etc/fstab
$ mount /myshare

将此部分添加到您的 /etc/samba/smb.conf 中

1
2
3
4
5
6
[myshare]
    path = /myshare
    writable = yes
  vfs objects = shadow_copy2
  shadow:snapdir = .snapshots
  shadow:sort = desc

重新加载 samba

1
$ /etc/init.d/samba reload

创建快照目录并运行脚本

1
2
3
4
5
6
$ mkdir -p /myshare/.snapshots
$ /etc/ceph/scripts/autosnap.sh
* Create snapshot for myshare: @GMT-2013.08.09-10.16.10-autosnap
synced, no cache, snapshot created.
* Shadow Copy to mount for rbd/myshare :
GMT-2013.08.09-10.14.44

验证第一个快照是否正确挂载

1
2
3
$ mount | grep myshare
/dev/rbd1 on /myshare type xfs (rw,relatime,attr2,inode64,sunit=8192,swidth=8192,noquota)
/dev/rbd2 on /myshare/.snapshots/@GMT-2013.08.09-10.14.44 type xfs (ro,relatime,nouuid,norecovery,attr2,inode64,sunit=8192,swidth=8192,noquota)

此外,您可以将其添加到 crontab 中,以每天运行该脚本

1
$ echo "00 0    * * *   root    /bin/bash /etc/ceph/scripts/autosnap.sh" >> /etc/crontab