在 XenServer 6.1 上使用 SSHFS

Icu*_*Icu 4 backup xen virtual-machines sshfs

在 Xen Server 6.1 上,为了备份我的 VM,我使用基于以下工具的脚本:

  • xe vm-list构建要备份的虚拟机列表
  • xe vm-snapshot拍摄虚拟机快照
  • xe template-param-set is-a-template=false ha-always-run=false将快照转换为虚拟机
  • xe vm-export vm=uuid_of_this_new_vm filename=|ssh ..... "cat > /path/backup.xva"
    --> 将导出发送到我的备份服务器而不将其存储在本地
  • xe vm-uninstall

我想使用 sshfs 在我的 Xen 主机上安装我的远程备份服务器。但 sshfs 在 Xen 发行版或默认存储库(XenServer 6.1.0 更新)中不可用。

我有几种在 Xen 主机上安装 sshfs 的可能性:

  • 我添加了一个包含 sshfs 的存储库。我想这会给我以后带来麻烦。Xen 不支持它,我更喜欢让主机配置大部分不变
  • 我可以拿一个 tarball 并将其安装在单独的目录中
  • 或者我采用 RPM 并将其分开安装

或者我找到了一种将远程 ssh 命令通过管道传输到的方法,xe vm-import就像我对导出所做的那样。我测试了很多东西但没有任何效果

您认为最好的解决方案是什么?

小智 5

虽然这是一个老问题,但我自己刚刚弄清楚了这个问题。

首先..什么不起作用(全部在 XenServer 6.5 上测试):

xe-import filename=/dev/stdin 根本不起作用。 您是否这样做并不重要:

# simple local import on xenhost
xe vm-import filename=/dev/stdin < myexport.xva

# try it the other way, with cat, still won't work:    
cat myexport.xva | xe vm-import filename=/dev/stdin

# and no, dd instead of cat in the above does not make it better

# nor can you pull the file from elsewhere via ssh:
ssh user@backupserver "cat myexport.xva" |  xe vm-import filename=/dev/stdin

# nor the other way, pushing from elsewhere to your xenserver
ssh root@xenhost "xe vm-import filename=/dev/stdin" < myexport.xva

# named pipes don't work either, even locally:
mkfifo mypipe
cat myexport.xva > ./mypipe &
xe vm-import filename=./mypipe
Run Code Online (Sandbox Code Playgroud)

所以,我发现无法从流导入,它必须是某种真正的文件系统。显然这曾经有效,但现在不行了。 我的猜测是xenserver想要寻求。

(如果有人能发现我的尝试中的缺陷并证明我错了,我将非常感激)。

所以,是的,我的结论是,您必须使用远程文件系统,并且我们知道 NFS 可以用于此目的,因为我们已经使用过它..但为了简单起见,决定使用 sshfs。以下是我在 XenServer 6.5 上安装 sshfs 的方法:

# fuse-fs and fuse-libs are in existing repos, so..
yum --enablerepo=base --disablerepo=citrix install fuse-fs
# for some reason yum wanted to install i386 fuse-libs which fails
# because of a dependency on i386 glibc.. nevermind all that, tell it
# directly that we want x86_64 and it will work:
yum --enablerepo=base --disablerepo=citrix install fuse-libs.x86_64

# fuse-sshfs is in the epel repo, which we need to add
yum --disablerepo=citrix --enablerepo=extras install epel-release
# now install fuse-sshfs
yum --disablerepo=citrix --enablerepo=extras install fuse-sshfs

# The above leaves epel-release enabled, which should be no problem but
# nevertheless I disabled it since I don't need it anymore:
#   Use vim to edit /etc/yum.repos.d/epel.repo
#   Where it says `enabled=1` change to `enabled=0`
vim /etc/yum.repos.d/epel.repo
Run Code Online (Sandbox Code Playgroud)

现在可以从另一台机器上的导出恢复:

# make mount point
mkdir backups

# mount location of your backups onto mount point
sshfs user@backupserver.mydomain.com:/path/to/backups backups

# import as usual
xe vm-import filename=backups/myexport.xva

# unmount the remote filesystem, if you don't need it anymore
umount backups

# IT WORKS
Run Code Online (Sandbox Code Playgroud)

哦,我应该补充一下..我尝试在我们的备份服务器上安装 xenxerver 工具..它也不起作用。当然,您可以执行命令,这一切看起来都很棒。但filename=/dev/stdin仍然不起作用,也不filename=/path/to/myexport.xva。它只是挂起或开始导入,然后以奇怪的方式失败。

这就是进口……但是出口呢?使用远程安装的xenserver工具:

xe vm-export uuid=the-vm-uuid 文件名= -s xenhost.my.domain -u root -pwf 密码文件

这确实导出到标准输出。但目前还不清楚这些出口是否总是能成功进口。我经历了一些失败和一些成功。所以决定根本不使用远程工具..而是通过 ssh 来实现:

ssh root@xenhost.my.domain "vm-export uuid=the-vm-uuid filename=" > myexport.xva
Run Code Online (Sandbox Code Playgroud)

有用!

这样做的结果是,使用我们的备份系统(Bareos),可以通过 ssh 直接备份到备份软件中,而无需先导出到临时文件。但要进行恢复,需要先将xva恢复到临时存储,然后使用sshfs挂载到xenhost上,然后vm-import。我很遗憾我们不能双向传输..希望这个问题能在某个时候在 xe 中得到解决。

希望这可以帮助一些人..需要大量的尝试和错误来测试所有的可能性:)