xen vm安装_如何使用Xen-Phoenix(Bash)免费还原Citrix-Xen VM

xen vm安装

xen vm安装

3040287674_c318f91f8d_z1

Have you ever had the need to bulk restore your Citrix-Xen VMs for a disaster recovery (DR) solution, or just to test that your backups are working? HTG explains how to use Xen-Phoenix, a free bash script, for VM restoring.

您是否曾经需要针对灾难恢复(DR)解决方案批量还原Citrix-Xen VM,或者只是为了测试备份是否正常工作? HTG解释了如何使用免费的bash脚本Xen-Phoenix进行VM还原。

Photo Credit: Ryan McCurdy via Compfight cc

图片来源: Ryan McCurdy通过Compfight cc

Like we’ve mentioned in “How To Backup Citrix Xen VMs for Free with Xen-pocalypse“, one of the nice things in Citrix Xen is that many of its features are free of charge. With that said, if you want the “Automated VM protection and recovery” feature, you would have to start paying for the “Advance” license. Again, it is not that we at HTG are dismissing the value of a true backup solution, but if you’re on a tight budget, have already gotten the VM images out of the hypervisor and are in need of a way to automate your “test restore”/”DR refresh” procedures, you might find Xen-Phoenix to be a perfectly reasonable solution before you make the budget commitment.

就像我们在“如何使用Xen-pocalypse如何免费备份Citrix Xen VM ”中提到的那样, Citrix Xen的优点之一就是它的许多功能都是免费的。 话虽如此,如果您想要“虚拟机自动保护和恢复”功能,则必须开始支付“高级”许可证。 同样,HTG并非不是在放弃真正的备份解决方案的价值,而是如果您的预算有限,则已经将VM映像从虚拟机管理程序中删除,并且需要一种自动执行“测试“还原” /“ DR刷新”过程,在做出预算承诺之前,您可能会发现Xen-Phoenix是一个完美的解决方案。

总览 (Overview )

The “use case”: You have a couple of VMs that require a restore. The importing in “Xen Center” using right clicks works ok, but you want this process to happen automatically and on a schedule. This Bash script uses the “XE” command to perform its duties. XE is the Xen command line interface (CLI), automatic equivalent for issuing the “right clicks” in the “Xen Center”. We will be calling the script from Cron which will supply the “scheduling” part. In its simplest form, the restore flow is:

“用例”:您有几个需要还原的VM。 使用右键单击在“ Xen Center”中导入可以正常进行,但是您希望此过程自动按计划进行。 该Bash脚本使用“ XE”命令执行其职责。 XE是Xen命令行界面(CLI),相当于在“ Xen Center”中发出“右键单击”的自动功能。 我们将从Cron调用脚本,该脚本将提供“计划”部分。 最简单的形式是:

  • Delete all* previously existing VMs on the server

    删除服务器上所有*先前存在的虚拟机

  • Import VMs from files in the backup location.

    从备份位置中的文件导入VM。
  • Verify that all VMs are operable by activating them one by one and looking for the guest tools heartbeat.

    通过逐个激活所有VM并查找来宾工具的心跳信号,验证所有VM是否可操作。
  • Turn VMs off when a heartbeat has been discovered, or a timeout has been reached.

    发现心跳或达到超时后,请关闭虚拟机。

*The delete all VMs behavior can be disabled completely and supports exceptions (see below).

*可以完全禁用删除所有VM行为,并支持例外(请参阅下文)。

Lets get cracking :)

让我们开始吧:)

获取脚本 (Obtain the script)

Xen-phoenix can be freely obtained from github, using the regular git methods. With that said, if you’re not versed in git yet, you can grab the zip file with this link. As the script needs to run on one of your Xen servers, you should extract it there so that execution permissions are preserved.

Xen-phoenix可以使用常规git方法从github免费获得。 话虽如此,如果您还不熟悉git ,则可以使用此链接来获取zip文件。 由于该脚本需要在您的Xen服务器之一上运行,因此您应该在该服务器上将其解压缩,以便保留执行权限。

wget https://github.com/aviadra/Xen-phoenix/archive/master.zip
unzip master

wget https://github.com/aviadra/Xen-phoenix/archive/master.zip
unzip master

While the above would work, you are advised to use the GIT method so that you may benefit from future updates.

尽管上述方法可行,但建议您使用GIT方法,以便将来可以从中受益。

出口地点 (The exports location)

We need to configure where to take the VM exports from.

我们需要配置从何处导出VM。

While randomly poking  around in Citrix Xen, I have found that the Storage Repositories (SRs) are available for use under “/var/run/sr-mount/%UUID%” where UUID is the unique identifier of the SR, which can be obtained from the GUI.

在Citrix Xen中随机访问时,我发现可以在“ / var / run / sr-mount /%UUID%”下使用存储库(SR),其中UUID是SR的唯一标识符,可以是从GUI获取。

This means we can use the regular “Next -> Next -> Finish” wizard to create the “mount” to the desired backup location, and then have the script use that path (as apposed to messing with mounting from the command line which is beyond the scope of this guide).

这意味着我们可以使用常规的“下一步->下一步->完成”向导来将“装载”创建到所需的备份位置,然后让脚本使用该路径(与从命令行进行装载有关)超出了本指南的范围)。

To Create a new “mount”, right click the server name and select New SR.

要创建新的“装载”,请右键单击服务器名称,然后选择“新建SR”。

xen-backup06

In this example, we will point Xen to a Windows share, so choose “Windows File Sharing (CIFS)”:

在此示例中,我们将Xen指向Windows共享,因此选择“ Windows File Sharing(CIFS)”:

xen-backup07

Complete the Next -> Next -> Finish.

完成下一步->下一步->完成。

Obtain the SR’s UUID

获取SR的UUID

To obtain an SR’s UUID, simply click on its name in the Xen Center and go to the “General” tab.

要获取SR的UUID,只需在Xen Center中单击其名称,然后转到“常规”标签。

xen-backup08

In order to copy the UUID, simply right click it and choose “copy”.

为了复制UUID,只需右键单击它并选择“复制”。

xen-backup09b

With this information at hand, you are ready to edit the settings file.

有了这些信息,您就可以编辑设置文件了。

配置设置文件 (Configure the Settings file)

The Xen-phoenix project comes bundled with a “settings” file template. This template should be edited to reflect your setup and passed as the first argument to the script.

Xen-phoenix项目捆绑了一个“设置”文件模板。 应该编辑此模板以反映您的设置,并将其作为第一个参数传递给脚本。

The settings file designates the following:

设置文件指定以下内容:

  • The location of the source exports – If you have followed the guide to this point, you only have to replace the %UUID% with the SR’s as it was obtained from above.

    源出口的位置–如果您已按照指南进行操作,则只需从上面获得的SR替换%UUID%即可。
  • The location of SendEmail  – If you have opted to enable Email, you need to input where you have extracted the perl executable here.

    SendEmail的位置–如果您选择启用电子邮件,则需要在此处输入提取perl可执行文件的位置。
  • Verifier — This controls the post restore verification procedure. This is enabled by default, as a successful “file level restore” doesn’t necessary mean a functional VM.

    验证程序—控制还原后验证过程。 默认情况下启用此功能,因为成功的“文件级还原”并不一定意味着功能正常的VM。
  • Server_prep — This controls the pre-restore deletion of all VMs on the DR server. This is enabled by default  because it is assumed that the DR server is a dedicated server for this purpose. If you need a VM that’s running on this server to not be deleted, configure it to be excluded. If this behavior is not suited for your situation, simply disable it completely.

    Server_prep-这控制灾难恢复服务器上所有VM的还原前删除。 默认情况下启用此功能,因为假定DR服务器是用于此目的的专用服务器。 如果您需要不删除在此服务器上运行的VM,请将其配置为排除。 如果此行为不适合您的情况,只需完全禁用它即可。

  • Email details — Again, if you have enabled email, you need to define details such as: To, From, Servername/IP & etc’.

    电子邮件详细信息-同样,如果启用了电子邮件,则需要定义详细信息,例如:收件人,发件人,服务器名/ IP等。

  • Debugging  – The default is to have debugging turned off with the value “0″ (zero). You should not need to turn this on, but if you do, more information is noted in the troubleshooting segment.

    调试–默认情况下,调试将关闭,其值为“ 0”(零)。 您不需要打开它,但是如果您这样做,则会在故障排除部分中指出更多信息。

执行 (Execution)

This script takes the settings file as its first argument and any other arguments as “Chevrons” to search for (separated by spaces). Chevrons, are “strings”, which support regular expressions which represent at least part of the desired file name of the VM export.

该脚本将设置文件作为其第一个参数,并将任何其他参数作为“ Chevrons ”进行搜索(以空格分隔)。 人字形是“字符串”,它们支持正则表达式,这些表达式至少表示VM导出所需文件名的一部分。

That is, in its simplest form, an invocation of Xen-phoenix would look like:

也就是说,以最简单的形式,对Xen-phoenix的调用将类似于:

./Xen-phoenix.sh settings.cfg DevTools

./Xen-phoenix.sh settings.cfg DevTools

Where in the case above, we are inside the directory that holds the script & the settings file and the “Chevron” the script will look for is “DevTools”. This will cause all the files in the exports directory with the string “DevTools” in their name to be imported.

在上述情况下,我们位于保存脚本和设置文件的目录中,脚本将查找的“ Chevron”为“ DevTools”。 这将导致导出目录中名称中带有字符串“ DevTools”的所有文件。

A more complex example can look like:

一个更复杂的示例如下所示:

./Xen-phoenix.sh settings.cfg [Aa][Dd] [Bb][iI] [Dd]ev[Tt]ools

./Xen-phoenix.sh settings.cfg [Aa][Dd] [Bb][iI] [Dd]ev[Tt]ools

Where in the example above, files that contain the word “devtools” spelled with a capital “D” and “T” or non-capital ones, as well as “AD” & “BI” with or without capitalization, will be imported.

在上面的示例中,将导入包含单词“ devtools”,大写字母“ D”和“ T”或非大写字母以及“ AD”和“ BI”(带有或不带有大写字母)的文件。

排程 (Scheduling)

As noted above, we will use Cron to schedule the execution. Before we go into the configuration, it is highly recommended that you configure the already installed SSMTP package on your Xen server. While this is an optional step, doing so will give you a “backwash” collector. Having such a “backwash collector” may alert you to things the script isn’t able to.

如上所述,我们将使用Cron安排执行时间。 在进行配置之前,强烈建议您在Xen服务器上配置已经安装的SSMTP软件包。 虽然这是可选步骤,但这样做将为您提供“反洗”收集器。 拥有这样的“反冲洗收集器”可能会提醒您脚本无法执行的操作。

Enter into cron’s editing mode by issuing:

通过发出以下命令进入cron的编辑模式:

crontab -e

crontab -e

If you have followed the instructions above and you want to add a scheduled backup for Sunday at 01:31 (1:31AM), input the below:

如果您已按照上面的说明进行操作,并且想要为周日的01:31(1:31 AM)添加计划的备份,请输入以下内容:

31 01 * * sun /root/Xen-phoenix-master/Xen-phoenix.sh /root/Xen-phoenix-master/settings.cfg [Aa][Dd] DB [Bb][iI] [Dd]ev[Tt]ools

31 01 * * sun /root/Xen-phoenix-master/Xen-phoenix.sh /root/Xen-phoenix-master/settings.cfg [Aa][Dd] DB [Bb][iI] [Dd]ev[Tt]ools

The above is correct assuming your script and settings file are both under “/root/Xen-phoenix-master/”.

如果您的脚本和设置文件都在“ / root / Xen-phoenix-master /”下,则以上内容是正确的。

获取SendEmail(可选) (Obtain SendEmail (optional))

We’ve written about the SendEmail perl program in the past, so there is no need to reiterate here. Suffice it to say, it works the same way on Linux as it does on Windows.

过去我们已经撰写了有关SendEmail perl程序的文章,因此无需在此重复。 可以说,它在Linux上的工作方式与Windows上的工作方式相同。

While enabling email is optional, it is highly recommended because then the script will be able to:

虽然启用电子邮件是可选的,但强烈建议您启用它,因为该脚本将能够:

  • Inform you when it started & finished running.

    开始运行并结束运行时通知您。
  • Alert you of any errors it was able to detect and handle.

    提醒您它能够检测和处理的任何错误。

Download it to the Xen server and extract.

将其下载到Xen服务器并解压缩。

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar xvzhf sendEmail-v1.56.tar.gz

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar xvzhf sendEmail-v1.56.tar.gz

Note the location where you extracted it to. You will need it for the settings file.

请注意将其提取到的位置。 设置文件将需要它。

定义“删除异常”标签(可选) (Defining the “Delete Exception” Tag (optional))

Xen-Phoenix takes a page from its ancestor (Xen-Pocalypse) and gives you the ability to granularly exclude a VM from the system-wide deletion using a control TAG. In order to do this, you need to define a new “Custom Field”.

Xen-Phoenix从其祖先(Xen-Pocalypse)提取了一个页面,并使您能够使用控件TAG从系统范围的删除中精细地排除VM。 为此,您需要定义一个新的“自定义字段”。

To do this, open the server’s or even a VM’s properties. In the navigation pane, select “Custom Fields”.

为此,请打开服务器甚至VM的属性。 在导航窗格中,选择“自定义字段”。

xen-backup01

If this is the first time you define a “custom field” (as in the example above), you will not have the “Phoenix_keeper” field to input data into, so you need to create it. To do this, click on “Edit Custom Fields” in the dialog box that pops up, then click on “Add…”

如果这是您首次定义“自定义字段”(如上例所示),则将没有“ Phoenix_keeper”字段可将数据输入到其中,因此需要创建它。 为此,请在弹出的对话框中单击“编辑自定义字段”,然后单击“添加…”

Xen-phoenix00

Create a “Text” type field with the name “Phoenix_keeper”.

创建一个名称为“ Phoenix_keeper”的“文本”类型字段。

Note: The name of the custom field has been “hard coded” into the script, so you MUST not deviate from the spelling above, unless you change the relevant code as well.

注意:自定义字段的名称已“硬编码”到脚本中,因此,除非您也更改了相关代码,否则不得偏离上面的拼写。

Once the field has been created, you should see:

创建字段后,您将看到:

Xen-phoenix01

Close the window. You should now have the “Phoenix_keeper” field to fill, as in the picture below.

关闭窗口。 您现在应该填写“ Phoenix_keeper”字段,如下图所示。

Xen-phoenix02

Now, all you have to do is populate this field with a remark (any remark will do), which will cause Xen-phoenix to skip it when deleting.

现在,您所要做的就是在该字段中添加一个备注(任何备注都可以),这将导致Xen-phoenix在删除时跳过它。

故障排除 (Troubleshooting)

While I’ve put a lot of effort into making the script as easy to use and as foolproof as possible, “the world is a bigger lab”. The information below may help you ascertain what is the source of your troubles.

尽管我已经尽了最大的努力来使脚本易于使用且非常简单,但“世界是一个更大的实验室”。 下面的信息可以帮助你确定是什么的来源你的烦恼

Logging

记录中

All “logging” is collected by the Xen host running the script in the syslog mechanism. This, of course, can be viewed with:

Xen主机通过syslog机制中的脚本来收集所有“日志记录”。 当然,可以通过以下方式查看:

less +F /var/log/messages

less +F /var/log/messages

You are looking for the key word “Xen-Phoenix”.

您正在寻找关键字“ Xen-Phoenix”。

Note: Citrix has set a two (2) day retention policy for syslog of its servers. You may want to keep that in mind for postmortems.

注意:Citrix已为其服务器的系统日志设置了两(2)天的保留策略。 您可能要记住事后验尸。

Debugging

调试

As noted in the settings file segment, there is a directive to enable debugging.  Enabling debugging will cause the script to output verbose logging to the console and castrate it from sending emails and actually performing the imports, unless the relevant flags are also set. The possible flags are noted in the settings file template, and they enable you to granularly define what you want to debug.

如设置文件部分所述,有一个指令可启用调试。 启用调试将导致脚本将详细的日志记录输出到控制台,并在发送电子邮件和实际执行导入之前对其进行cast割,除非也设置了相关标志。 可能的标志在设置文件模板中注明,它们使您能够细化定义要调试的内容。

It is my hope that you haven’t needed any debugging and you are reaping the fruits of my labor :)

我希望您不需要任何调试,并且正在收获我的劳动成果:)



Just think of all the poverty, the hatred and the lies, And imagine the destruction of all that you despise. Slowly from the ashes, the phoenix will arise…

只要想一想所有的贫穷,仇恨和谎言,然后想象一下您所鄙视的一切的破坏。 凤凰从灰烬中慢慢冒出来……

翻译自: https://www.howtogeek.com/161968/how-to-restore-citrix-xen-vms-for-free-with-xen-phoenix-bash/

xen vm安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值