Advertisement
Guest User

Untitled

a guest
Jan 27th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import commands, time, subprocess
  4.  
  5. def get_backup_vms():
  6. result = []
  7.  
  8. cmd = "xe vm-list is-control-domain=false is-a-snapshot=false"
  9. output = commands.getoutput(cmd)
  10.  
  11. for vm in output.split("\n\n\n"):
  12. lines = vm.splitlines()
  13. uuid = lines[0].split(":")[1][1:]
  14. name = lines[1].split(":")[1][1:]
  15. result += [(uuid, name)]
  16.  
  17. return result
  18.  
  19. def backup_vm(uuid, filename, timestamp):
  20. cmd = "xe vm-snapshot uuid=" + uuid + " new-name-label=" + timestamp
  21. snapshot_uuid = commands.getoutput(cmd)
  22.  
  23. cmd = "xe template-param-set is-a-template=false ha-always-run=false uuid=" + snapshot_uuid
  24. commands.getoutput(cmd)
  25.  
  26. cmd = "xe vm-export vm=" + snapshot_uuid + " filename=" + filename
  27. commands.getoutput(cmd)
  28.  
  29. cmd = "xe vm-uninstall uuid=" + snapshot_uuid + " force=true"
  30. commands.getoutput(cmd)
  31.  
  32.  
  33. cmd = "mount -t nfs 192.168.0.51:/storage/backup/xenserver/arara01 /mnt/nfs"
  34. commands.getoutput(cmd)
  35. for (uuid, name) in get_backup_vms():
  36. timestamp = time.strftime("%d%m%Y-%H%M", time.gmtime())
  37. print timestamp, uuid, name
  38. filename = "\"/mnt/nfs/" + timestamp + "" + name + ".xva\""
  39. backup_vm(uuid, filename, timestamp)
  40. subprocess.call(['./backup_clean.sh'])
  41. cmd = "umount /mnt/nfs"
  42. commands.getoutput(cmd)
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. ######################### CONTENT SHELL #####################
  52.  
  53.  
  54. #!/bin/bash
  55.  
  56. echo "Subject: Storage Clean "
  57.  
  58. umount /mnt/nfs
  59. mount -t nfs 192.168.0.51:/storage/backup/xenserver/arara01 /mnt/nfs
  60. find /mnt/nfs/*.xva -mtime -1 -exec rm -rif {} \;
  61.  
  62. echo "END"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement