LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Backup XenServer VMs (http://www.linuxquestions.org/questions/linux-server-73/backup-xenserver-vms-862886/)

Mustafa Ismail Mustafa 02-15-2011 01:30 PM

Backup XenServer VMs
 
OK, so I've been using Andy Burton's fantastic XenServer VM backup script (Clickety) and the only fault I can find is not script based but XenServer. If you try and overwrite an already existing backed up VM, XenServer seems to ignore that.

So, I decided to tackle the situation by doing the following:

Grab a list of the files that already exist and serializing that list
Perform the actual VM backups
Delete the original files that are in the serialized file
Delete the serialized file itself
And I'm trying to improve my python-fu so I decided to do this (1,3 and 4) with python scripts and still do the backup with Andy's, possibly moving to my own python script in the future.

Now I have a pair of scripts, prebak.py and postbak.py as follows:

prebak.py:

Code:

#!/usr/bin/python

import os
import glob

path = "/home/mim/scripts/python/junk/"
ext = "del"
tmpList = "tmpList"



#create a file with the list of files to remove
#fileList = [file for file in os.listdir(path) if file.endswith(ext)]
fileList = glob.glob(path+"*."+ext)

tmpfile = open(path+tmpList,"w")
for i in fileList:
    tmpfile.write(i+"/n")
tmpfile.close()

#END

postbak.py

Code:

#!/usr/bin/python

import os
import glob

path = "/home/mim/scripts/python/junk/"
ext = "del"
tmpList = "tmpList"


#read from the tmpList and delete each file then the tmplist itself
tmpfile = open(path+tmpList,"r")
fileList = tmpfile.readlines()
print fileList
for i in fileList:
#    print(i)
#delete the tmpList
os.remove(i)

#remove the tmplist file
os.remove(path+tmpList)
#END

(please note that there has been some experimentation with the code and the values in there are dummy values for testing before moving to production)

My two questions:

How can I serialize and deserialize the values I retrieve from glob in list format?
Is there a better way of doing this?
This is being run on Python 2.4.3 (the version I found on XenServer 5.x)

TIA

EDIT:

Oh yeah, I also thought of doing some smart redirections along the lines of:

Code:

ls /path/to/files/*.extension > /path/to/tmpfolder/list.lst
then later

redirect the contents of the files to a "xargs rm" but I wasn't too sure how to do that.


All times are GMT -5. The time now is 10:45 PM.