blog.hamels.be

  • Blog

blog.hamels.be

  • Blog
General, XenServer,

Backup your XenServer virtual machines with a simple cli script

by PieterJuly 21, 2015no comment
0
Shares
Share on FacebookShare on Twitter

As I was looking for a simple script to backup my virtual machines on XenServer, I came across a script and modified it a little bit.
This script backups your virtual machines to a NFS server.

You need to modify the NFS parameters and create the mount point to use it.

Here’s the simple Python script:

#!/usr/bin/python

import commands, time

def get_backup_vms():
   result = []

   cmd = "xe vm-list is-control-domain=false is-a-snapshot=false"
   output = commands.getoutput(cmd)

   for vm in output.split("\n\n\n"):
      lines = vm.splitlines()
      uuid = lines[0].split(":")[1][1:]
      name = lines[1].split(":")[1][1:]
      result += [(uuid, name)]

   return result

def backup_vm(uuid, filename, timestamp):
   cmd = "xe vm-snapshot uuid=" + uuid + " new-name-label=" + timestamp
   snapshot_uuid = commands.getoutput(cmd)

   cmd = "xe template-param-set is-a-template=false ha-always-run=false uuid=" + snapshot_uuid
   commands.getoutput(cmd)

   cmd = "xe vm-export vm=" + snapshot_uuid + " filename=" + filename
   commands.getoutput(cmd)

   cmd = "xe vm-uninstall uuid=" + snapshot_uuid + " force=true"
   commands.getoutput(cmd)


cmd = "mount -t nfs 192.168.100.10:/vm-backups /mnt/nfs-backup"
commands.getoutput(cmd)
for (uuid, name) in get_backup_vms():
   timestamp = time.strftime("%Y%m%d-%H%M", time.gmtime())
   print timestamp, uuid, name
   filename = "\"/mnt/nfs-backup/" + timestamp + " " + name + ".xva\""
   backup_vm(uuid, filename, timestamp)
cmd = "umount /mnt/nfs-backup"
commands.getoutput(cmd)

Download the script here:

XenServer VM Backup Script (221 downloads)

 

Enjoy !

 

Next

Laravel 5.1 and socialite oauth

August 17, 2015

Related posts

covid19
General,

Covid-19 / Coronavirus statistics scraper

by PieterMarch 21, 2020no comment
logo-small
General, Security,

KRACK Vulnerability makes WiFi insecure

by PieterOctober 17, 2017no comment
wannacry-screencap_thumb800
General, Security,

Decryption tool for WannaCry

by PieterMay 19, 2017no comment
trackerearth
Android, General,

Android App: Road Trip Tracker

by PieterMay 10, 2017no comment

© 2020 webXtend.be. All rights reserved.