mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
added check for backup verification before delete
This commit is contained in:
parent
d1620f116c
commit
47f4b16571
@ -15,6 +15,7 @@ class XbmcBackup:
|
|||||||
xbmc_vfs = None
|
xbmc_vfs = None
|
||||||
remote_vfs = None
|
remote_vfs = None
|
||||||
restoreFile = None
|
restoreFile = None
|
||||||
|
remote_base_path = None
|
||||||
|
|
||||||
#for the progress bar
|
#for the progress bar
|
||||||
progressBar = None
|
progressBar = None
|
||||||
@ -32,21 +33,25 @@ class XbmcBackup:
|
|||||||
|
|
||||||
def configureRemote(self):
|
def configureRemote(self):
|
||||||
if(utils.getSetting('remote_selection') == '1'):
|
if(utils.getSetting('remote_selection') == '1'):
|
||||||
|
self.remote_base_path = utils.getSetting('remote_path_2');
|
||||||
self.remote_vfs = XBMCFileSystem(utils.getSetting('remote_path_2'))
|
self.remote_vfs = XBMCFileSystem(utils.getSetting('remote_path_2'))
|
||||||
utils.setSetting("remote_path","")
|
utils.setSetting("remote_path","")
|
||||||
elif(utils.getSetting('remote_selection') == '0'):
|
elif(utils.getSetting('remote_selection') == '0'):
|
||||||
|
self.remote_base_path = utils.getSetting('remote_path');
|
||||||
self.remote_vfs = XBMCFileSystem(utils.getSetting("remote_path"))
|
self.remote_vfs = XBMCFileSystem(utils.getSetting("remote_path"))
|
||||||
elif(utils.getSetting('remote_selection') == '2'):
|
elif(utils.getSetting('remote_selection') == '2'):
|
||||||
|
self.remote_base_path = "/"
|
||||||
self.remote_vfs = DropboxFileSystem("/")
|
self.remote_vfs = DropboxFileSystem("/")
|
||||||
|
|
||||||
def listBackups(self):
|
def listBackups(self):
|
||||||
result = list()
|
result = []
|
||||||
|
|
||||||
#get all the folders in the current root path
|
#get all the folders in the current root path
|
||||||
dirs,files = self.remote_vfs.listdir(self.remote_vfs.root_path)
|
dirs,files = self.remote_vfs.listdir(self.remote_base_path)
|
||||||
|
|
||||||
for aDir in dirs:
|
for aDir in dirs:
|
||||||
result.append(aDir)
|
if(self.remote_vfs.exists(self.remote_base_path + aDir + "/xbmcbackup.val")):
|
||||||
|
result.append(aDir)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -55,11 +60,9 @@ class XbmcBackup:
|
|||||||
|
|
||||||
def run(self,mode=-1,runSilent=False):
|
def run(self,mode=-1,runSilent=False):
|
||||||
#append backup folder name
|
#append backup folder name
|
||||||
remote_base_path = ""
|
|
||||||
progressBarTitle = utils.getString(30010) + " - "
|
progressBarTitle = utils.getString(30010) + " - "
|
||||||
if(mode == self.Backup and self.remote_vfs.root_path != ''):
|
if(mode == self.Backup and self.remote_vfs.root_path != ''):
|
||||||
#capture base path for backup rotation
|
self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d") + "/")
|
||||||
remote_base_path = self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d") + "/")
|
|
||||||
progressBarTitle = progressBarTitle + utils.getString(30016)
|
progressBarTitle = progressBarTitle + utils.getString(30016)
|
||||||
elif(mode == self.Restore and self.restore_point != None and self.remote_vfs.root_path != ''):
|
elif(mode == self.Restore and self.restore_point != None and self.remote_vfs.root_path != ''):
|
||||||
self.remote_vfs.set_root(self.remote_vfs.root_path + self.restore_point + "/")
|
self.remote_vfs.set_root(self.remote_vfs.root_path + self.restore_point + "/")
|
||||||
@ -87,6 +90,9 @@ class XbmcBackup:
|
|||||||
#make the remote directory
|
#make the remote directory
|
||||||
self.remote_vfs.mkdir(self.remote_vfs.root_path)
|
self.remote_vfs.mkdir(self.remote_vfs.root_path)
|
||||||
|
|
||||||
|
#create a validation file for backup rotation
|
||||||
|
self._createValidationFile()
|
||||||
|
|
||||||
utils.log(utils.getString(30051))
|
utils.log(utils.getString(30051))
|
||||||
allFiles = []
|
allFiles = []
|
||||||
fileManager = FileManager(self.xbmc_vfs)
|
fileManager = FileManager(self.xbmc_vfs)
|
||||||
@ -163,22 +169,7 @@ class XbmcBackup:
|
|||||||
self.backupFiles(fileGroup['files'],self.xbmc_vfs,self.remote_vfs)
|
self.backupFiles(fileGroup['files'],self.xbmc_vfs,self.remote_vfs)
|
||||||
|
|
||||||
#remove old backups
|
#remove old backups
|
||||||
total_backups = int(utils.getSetting('backup_rotation'))
|
self._rotateBackups()
|
||||||
if(total_backups > 0):
|
|
||||||
|
|
||||||
dirs,files = self.remote_vfs.listdir(remote_base_path)
|
|
||||||
if(len(dirs) > total_backups):
|
|
||||||
#remove backups to equal total wanted
|
|
||||||
dirs.sort()
|
|
||||||
remove_num = len(dirs) - total_backups - 1
|
|
||||||
self.filesTotal = self.filesTotal + remove_num + 1
|
|
||||||
|
|
||||||
#update the progress bar if it is available
|
|
||||||
while(remove_num >= 0 and not self._checkCancel()):
|
|
||||||
self._updateProgress(utils.getString(30054) + " " + dirs[remove_num])
|
|
||||||
utils.log("Removing backup " + dirs[remove_num])
|
|
||||||
self.remote_vfs.rmdir(remote_base_path + dirs[remove_num] + "/")
|
|
||||||
remove_num = remove_num - 1
|
|
||||||
|
|
||||||
elif (mode == self.Restore):
|
elif (mode == self.Restore):
|
||||||
utils.log(utils.getString(30023) + " - " + utils.getString(30017))
|
utils.log(utils.getString(30023) + " - " + utils.getString(30017))
|
||||||
@ -317,6 +308,32 @@ class XbmcBackup:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _rotateBackups(self):
|
||||||
|
total_backups = int(utils.getSetting('backup_rotation'))
|
||||||
|
if(total_backups > 0):
|
||||||
|
#get a list of valid backup folders
|
||||||
|
dirs = self.listBackups()
|
||||||
|
|
||||||
|
if(len(dirs) > total_backups):
|
||||||
|
#remove backups to equal total wanted
|
||||||
|
dirs.sort()
|
||||||
|
remove_num = len(dirs) - total_backups - 1
|
||||||
|
self.filesTotal = self.filesTotal + remove_num + 1
|
||||||
|
|
||||||
|
#update the progress bar if it is available
|
||||||
|
while(remove_num >= 0 and not self._checkCancel()):
|
||||||
|
self._updateProgress(utils.getString(30054) + " " + dirs[remove_num])
|
||||||
|
utils.log("Removing backup " + dirs[remove_num])
|
||||||
|
self.remote_vfs.rmdir(self.remote_base_path + dirs[remove_num] + "/")
|
||||||
|
remove_num = remove_num - 1
|
||||||
|
|
||||||
|
def _createValidationFile(self):
|
||||||
|
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),'w')
|
||||||
|
vFile.write("XBMC Backup Validation File");
|
||||||
|
vFile.close()
|
||||||
|
|
||||||
|
self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),self.remote_vfs.root_path + "xbmcbackup.val")
|
||||||
|
|
||||||
class FileManager:
|
class FileManager:
|
||||||
fileArray = []
|
fileArray = []
|
||||||
not_dir = ['.zip','.xsp','.rar']
|
not_dir = ['.zip','.xsp','.rar']
|
||||||
|
Loading…
Reference in New Issue
Block a user