{"id":9471,"date":"2020-05-04T18:54:10","date_gmt":"2020-05-04T08:54:10","guid":{"rendered":"https:\/\/nsrd.info\/blog\/?p=9471"},"modified":"2020-05-04T18:54:13","modified_gmt":"2020-05-04T08:54:13","slug":"automated-testing-of-virtual-machine-recoveries-using-networker","status":"publish","type":"post","link":"https:\/\/nsrd.info\/blog\/2020\/05\/04\/automated-testing-of-virtual-machine-recoveries-using-networker\/","title":{"rendered":"Automated Testing of Virtual Machine Recoveries using NetWorker"},"content":{"rendered":"\n<p>While Avamar has options for automating the test of virtual machine recoveries, it&#8217;s not functionality that&#8217;s present in NetWorker.<\/p>\n\n\n\n<p>Recently I was contacted by Ugo Bellavance: would I be interested in checking out a script he&#8217;d written to automate testing of virtual machine recoveries. Interested? <strong>You bet! <\/strong><\/p>\n\n\n\n<p><em>At the end of the post I&#8217;ve got a link to Ugo&#8217;s blog post and Github for the script, but I&#8217;ll set your appetite by going through an example use of it in my lab.<\/em><\/p>\n\n\n\n<p>As it stands, here&#8217;s how it works: you provide the script some details about your vCenter\/ESX environment and the virtual machine you want to do a recovery test against. In the spirit of <em>good<\/em> randomised testing, the script picks a random backup or clone of the virtual machine and runs the recovery for you.<\/p>\n\n\n\n<p>Here&#8217;s the details you need to provide the script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Sun May 03 15:49:20]\n[\u2022 ~\/nwautomatedrecover-master \u2022]\nroot@orilla\n\n$ <strong>.\/nwrestvmrecover -h<\/strong>\nnwrestvmrecover [OPTION]\u2026 [-x] vmname - Script to trigger a restore via the Networker REST API\nwhere:\n-h shows this help text\n-a Authentication digest\n-b Networker (backup) server name\n-c Destination cluster resource\n-d Destination datacenter\n-e Destination (ESXi) host\n-f VM Folder\n-j Job name\n-n VM name (once recovered, destination)\n-p Power on after recover?\n-r Reconnect NIC after recover?\n-s Destination datastore\n-v vCenter Server\n-x Must be present to confirm that the recover must be executed\n\nvmname : Name of the Virtual Machine to recover (source)\nAll the parameters are required by this script (but may not be by the API)\n\nNote: Always test in a lab first<\/pre>\n\n\n\n<p>I had to make one minor modification to get the correct results in my lab \u2014\u00a0I changed the script&#8217;s invoked JSON to instead reference the compute resource instead of the cluster compute resource, given I don&#8217;t have a cluster in my lab. (For a business user of the script, that&#8217;s likely a modification they won&#8217;t need to make.) Here&#8217;s an example of running the script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ .\/nwrestvmrecover -a <em>base64EncodedCredentials<\/em> -b orilla -c domain-s26 -d datacenter-21 -e host-28 -f group-v22 -j Vulcan_RecMay3 -p false -r false -s datastore-32 -v oaktier.turbamentis.int -n vulcanTestMay3 -x vulcan\n\n==================================================\nHere are the values of the parameters you entered:\n\nServer = orilla\nVM to recover = vulcan\nAuth = xxxx\nvCenter Server = oaktier.turbamentis.int\nRecover Datastore = datastore-32\nCluster Compute Res. = domain-s26\nDatacenter = datacenter-21\nHost = host-28\nVMFolder = group-v22\nDestination VMname = vulcanTestMay3\nJobName = Vulcan_RecMay3\nPowerOn = false\nReconnectNIC = false\n\nGetting the uuid of the VM to recover\u2026\n\nVM uuid = 500f21cd-5865-dc0d-7fe5-9b93fad1a059\n\nGetting the number of available backups\u2026\n\nNumber of available backups: 103\n\nPicking a random backup to recover from\u2026\n\nRandom Backup = 51\n\nGetting the backup ID of the randomly selected backup\u2026\n\nBackup ID = 292e9504-00000006-4a7a207b-5e7a207b-02b75000-9f778f56\n\nChoosing randomly if we restore from a backup or a clone\u2026\n\nValue of the cloneornot variable: 1. If the value is 0, it will restore from a backup. If the value is 1, it will restore from a clone\n\nGetting the backup instance ID (That's the ID of the clone or backup)\u2026\n\nRecover URL = https:\/\/orilla:9090\/nwrestapi\/v3\/global\/vmware\/vcenters\/oaktier.turbamentis.int\/protectedvms\/500f21cd-5865-dc0d-7fe5-9b93fad1a059\/backups\/292e9504-00000006-4a7a207b-5e7a207b-02b75000-9f778f56\/instances\/1585063094\/op\/recover\n\nInstance is clone? = true\n\nGetting disk list from the backup\u2026\n\nHere's the contents of the JSON that will be sent to the REST API:\n\n==================================================================\n\n{\n\"recoverMode\": \"New\",\n\"computeResourceMoref\": \"domain-s26\",\n\"datacenterMoref\": \"datacenter-21\" ,\n\"datastoreMoref\": \"datastore-32\",\n\"vCenterHostname\": \"oaktier.turbamentis.int\",\n\"hostMoref\": \"host-28\",\n\"vmFolderMoref\": \"group-v22\",\n\"vmName\": \"vulcanTestMay3\",\n\"jobName\": \"Vulcan_RecMay3\",\n\"powerOn\": \"false\",\n\"disks\": [\n{\n\"name\": \"Hard disk 1\",\n\"key\": \"2000\",\n\"datastoreMoref\": \"datastore-32\"\n}\n],\n\"reconnectNic\": \"false\"\n}\n\n================================================================\n\nExecuting the REST call, here is the output:\n\nAbout to connect() to orilla port 9090 (#0)\nTrying 192.168.100.4\u2026 connected\nConnected to orilla (192.168.100.4) port 9090 (#0)<\/pre>\n\n\n\n<p>I&#8217;ve trimmed the remainder of the output. Continuing the REST API theme, here&#8217;s my <em>webwatch<\/em> CGI output capturing the recovery in progress:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"3364\" height=\"1756\" src=\"https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover.png\" alt=\"\" class=\"wp-image-9472\" srcset=\"https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover.png 3364w, https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover-300x157.png 300w, https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover-1024x535.png 1024w, https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover-768x401.png 768w, https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover-1536x802.png 1536w, https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/webwatch_nwautomatedrecover-2048x1069.png 2048w\" sizes=\"auto, (max-width: 3364px) 100vw, 3364px\" \/><figcaption>Randomised Virtual Machine Recovery in Progress<\/figcaption><\/figure>\n\n\n\n<p>For the script, you do have to use the VMware internal identifiers for resources \u2014&nbsp;my datastore I wanted to recover to (&#8216;datastore4-ssd&#8217;) is actually datastore-32 as far as VMware is concerned. (Handily, Ugo has provided details on how to do this mapping \u2014&nbsp;and you can always also do a one-off recovery using NetWorker, with debug mode level 9, to see the details captured: remember since this is automated recovery testing, you&#8217;ll likely be recovering <em>to<\/em> a specific location all the time, regardless of what virtual machine you choose.)<\/p>\n\n\n\n<p>Ugo has a blog post introducing his utility, and links to his Github project for it <a href=\"https:\/\/lubik.blogspot.com\/2020\/05\/networker-automated-recovery-testing.html\" target=\"_blank\" aria-label=\"here \u2014&nbsp;please check it out (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"aioseop-link\"><strong>here \u2014&nbsp;please check it out<\/strong><\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While Avamar has options for automating the test of virtual machine recoveries, it&#8217;s not functionality that&#8217;s present in NetWorker. Recently&hellip;<\/p>\n","protected":false},"author":1,"featured_media":9473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,19,20,1357],"tags":[1252,1317,994,1087],"class_list":["post-9471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networker","category-recovery","category-scripting","category-vproxy","tag-recovery","tag-rest-api","tag-testing","tag-vmware"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/nsrd.info\/blog\/wp-content\/uploads\/2020\/05\/bigStock-Robot-with-Servers.jpg","jetpack_shortlink":"https:\/\/wp.me\/pKpIN-2sL","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/posts\/9471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/comments?post=9471"}],"version-history":[{"count":2,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/posts\/9471\/revisions"}],"predecessor-version":[{"id":9475,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/posts\/9471\/revisions\/9475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/media\/9473"}],"wp:attachment":[{"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/media?parent=9471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/categories?post=9471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nsrd.info\/blog\/wp-json\/wp\/v2\/tags?post=9471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}