Skip to content

Commit

Permalink
Raising errors if a snapshot still exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bunop committed Mar 8, 2016
1 parent a20abdd commit 5aa8677
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
14 changes: 13 additions & 1 deletion Lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ def dumpXML(self, path):

#call getDisk to get the disks to do snapshot
return dumpXML(domain, path)

def hasCurrentSnapshot(self):
"""call hasCurrentSnapshot on domain class attribute"""

#get my domain
domain = self.getDomain()

if domain.hasCurrentSnapshot() == 0:
return False

else:
return True

def getSnapshotXML(self):
"""Since I need to do a Snapshot with a XML file, I will create an XML to call
Expand Down Expand Up @@ -314,8 +326,8 @@ def __snapshotDelete(self):

#from https://bitbucket.org/russellballestrini/virt-back
def rotate( target, retention = 3 ):

"""file rotation routine"""

for i in range( retention-2, 0, -1 ): # count backwards
old_name = "%s.%s" % ( target, i )
new_name = "%s.%s" % ( target, i + 1 )
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
* verbosity level
* copy CD-rom data
* testing wrong configurations
* Snapshotting only a defined domain
28 changes: 22 additions & 6 deletions kvmBackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def filterDomains(domains, user_domains):
def backup(domain, parameters, backupdir):
"""Do all the operation needed for backup"""

# create a snapshot instance
snapshot = helper.Snapshot(domain)

# check if no snapshot are defined
if snapshot.hasCurrentSnapshot() is True:
raise Exception, "Domain '%s' has already a snapshot" %(domain)

#changing directory
olddir = os.getcwd()
workdir = os.path.join(backupdir, domain)
Expand Down Expand Up @@ -135,9 +142,6 @@ def backup(domain, parameters, backupdir):

tar = tarfile.open( tar_path, tar_mode )

#create a snapshot instance
snapshot = helper.Snapshot(domain)

#call dumpXML
xml_files = snapshot.dumpXML(path=datadir)

Expand All @@ -159,7 +163,7 @@ def backup(domain, parameters, backupdir):
#call snapshot
snapshot.callSnapshot()

logger.info("Adding image files for '%s' to archive %'s'" %(domain, tar_path))
logger.info("Adding image files for '%s' to archive '%s'" %(domain, tar_path))

#copying file
for disk, source in snapshot.disks.iteritems():
Expand Down Expand Up @@ -210,6 +214,9 @@ def backup(domain, parameters, backupdir):
#logging notice
sys.stderr.write(notice)
sys.stderr.flush()

# a flat to test if there were errors
flag_errors = False

#Starting software
logger.info("Starting '%s'" %(prog_name))
Expand Down Expand Up @@ -257,7 +264,13 @@ def backup(domain, parameters, backupdir):
domain_backup = True

#do backup stuff
backup(domain_name, parameters, backupdir)
try:
backup(domain_name, parameters, backupdir)

except Exception, message:
logger.exception(message)
logger.error("Domain '%s' was not backed up" %(domain_name))
flag_errors = True

#breaking cicle
break
Expand All @@ -266,4 +279,7 @@ def backup(domain, parameters, backupdir):
logger.debug("Ignoring '%s' domain" %(domain_name))

#end of the program
logger.info("'%s' completed successfully" %(prog_name))
if flag_errors is False:
logger.info("'%s' completed successfully" %(prog_name))
else:
logger.warn("'%s' completed with error(s)" %(prog_name))

0 comments on commit 5aa8677

Please sign in to comment.