Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import commands, time, subprocess
- 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.0.51:/storage/backup/xenserver/arara01 /mnt/nfs"
- commands.getoutput(cmd)
- for (uuid, name) in get_backup_vms():
- timestamp = time.strftime("%d%m%Y-%H%M", time.gmtime())
- print timestamp, uuid, name
- filename = "\"/mnt/nfs/" + timestamp + "" + name + ".xva\""
- backup_vm(uuid, filename, timestamp)
- subprocess.call(['./backup_clean.sh'])
- cmd = "umount /mnt/nfs"
- commands.getoutput(cmd)
- ######################### CONTENT SHELL #####################
- #!/bin/bash
- echo "Subject: Storage Clean "
- umount /mnt/nfs
- mount -t nfs 192.168.0.51:/storage/backup/xenserver/arara01 /mnt/nfs
- find /mnt/nfs/*.xva -mtime -1 -exec rm -rif {} \;
- echo "END"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement