mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
added backup rotation closes #10
This commit is contained in:
parent
a3724657c7
commit
272ea8b8a9
@ -32,6 +32,7 @@
|
|||||||
<string id="30051">Creating Files List</string>
|
<string id="30051">Creating Files List</string>
|
||||||
<string id="30052">Writing file</string>
|
<string id="30052">Writing file</string>
|
||||||
<string id="30053">Starting scheduled backup</string>
|
<string id="30053">Starting scheduled backup</string>
|
||||||
|
<string id="30054">Removing backup</string>
|
||||||
|
|
||||||
<string id="30060">Enable Scheduler</string>
|
<string id="30060">Enable Scheduler</string>
|
||||||
<string id="30061">Schedule</string>
|
<string id="30061">Schedule</string>
|
||||||
|
@ -86,6 +86,7 @@ class XbmcBackup:
|
|||||||
Restore = 1
|
Restore = 1
|
||||||
|
|
||||||
local_path = ''
|
local_path = ''
|
||||||
|
remote_root = ''
|
||||||
remote_path = ''
|
remote_path = ''
|
||||||
restoreFile = None
|
restoreFile = None
|
||||||
|
|
||||||
@ -100,17 +101,17 @@ class XbmcBackup:
|
|||||||
self.local_path = xbmc.makeLegalFilename(xbmc.translatePath("special://home"),False);
|
self.local_path = xbmc.makeLegalFilename(xbmc.translatePath("special://home"),False);
|
||||||
|
|
||||||
if(utils.getSetting('remote_selection') == '1'):
|
if(utils.getSetting('remote_selection') == '1'):
|
||||||
self.remote_path = utils.getSetting('remote_path_2')
|
self.remote_root = 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_path = utils.getSetting("remote_path")
|
self.remote_root = utils.getSetting("remote_path")
|
||||||
|
|
||||||
#fix slashes
|
#fix slashes
|
||||||
self.remote_path = self.remote_path.replace("\\","/")
|
self.remote_root = self.remote_root.replace("\\","/")
|
||||||
|
|
||||||
#check if trailing slash is included
|
#check if trailing slash is included
|
||||||
if(self.remote_path[-1:] != "/"):
|
if(self.remote_root[-1:] != "/"):
|
||||||
self.remote_path = self.remote_path + "/"
|
self.remote_root = self.remote_root + "/"
|
||||||
|
|
||||||
utils.log(utils.getString(30046))
|
utils.log(utils.getString(30046))
|
||||||
|
|
||||||
@ -125,10 +126,10 @@ class XbmcBackup:
|
|||||||
mode = int(utils.getSetting('addon_mode'))
|
mode = int(utils.getSetting('addon_mode'))
|
||||||
|
|
||||||
#append backup folder name
|
#append backup folder name
|
||||||
if(mode == self.Backup and self.remote_path != ''):
|
if(mode == self.Backup and self.remote_root != ''):
|
||||||
self.remote_path = self.remote_path + time.strftime("%Y%m%d") + "/"
|
self.remote_path = self.remote_root + time.strftime("%Y%m%d") + "/"
|
||||||
elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_path != ''):
|
elif(mode == self.Restore and utils.getSetting("backup_name") != '' and self.remote_root != ''):
|
||||||
self.remote_path = self.remote_path + utils.getSetting("backup_name") + "/"
|
self.remote_path = self.remote_root + utils.getSetting("backup_name") + "/"
|
||||||
else:
|
else:
|
||||||
self.remote_path = ""
|
self.remote_path = ""
|
||||||
|
|
||||||
@ -146,6 +147,25 @@ class XbmcBackup:
|
|||||||
utils.log(utils.getString(30050))
|
utils.log(utils.getString(30050))
|
||||||
|
|
||||||
self.syncFiles()
|
self.syncFiles()
|
||||||
|
|
||||||
|
#remove old backups
|
||||||
|
total_backups = int(utils.getSetting('backup_rotation'))
|
||||||
|
if(total_backups > 0):
|
||||||
|
|
||||||
|
dirs,files = xbmcvfs.listdir(self.remote_root)
|
||||||
|
if(len(dirs) > total_backups):
|
||||||
|
#remove backups to equal total wanted
|
||||||
|
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])
|
||||||
|
xbmcvfs.rmdir(self.remote_root + dirs[remove_num] + "/",True)
|
||||||
|
remove_num = remove_num - 1
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
utils.log(utils.getString(30023) + " - " + utils.getString(30017))
|
utils.log(utils.getString(30023) + " - " + utils.getString(30017))
|
||||||
self.fileManager = FileManager(self.remote_path)
|
self.fileManager = FileManager(self.remote_path)
|
||||||
@ -215,4 +235,4 @@ class XbmcBackup:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def isReady(self):
|
def isReady(self):
|
||||||
return True if self.remote_path != '' else False
|
return True if self.remote_root != '' else False
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<setting id="remote_path_2" type="text" label="30024" default="" visible="eq(-1,1)" />
|
<setting id="remote_path_2" type="text" label="30024" default="" visible="eq(-1,1)" />
|
||||||
<setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" />
|
<setting id="remote_path" type="folder" label="30020" visible="eq(-2,0)" />
|
||||||
<setting id="backup_name" type="text" label="30021" default="backup_date" visible="eq(-4,1)"/>
|
<setting id="backup_name" type="text" label="30021" default="backup_date" visible="eq(-4,1)"/>
|
||||||
|
<setting id="backup_rotation" type="number" label="Backups to keep (0 for all)" default="0" />
|
||||||
<setting id="run_silent" type="bool" label="30022" default="false" />
|
<setting id="run_silent" type="bool" label="30022" default="false" />
|
||||||
</category>
|
</category>
|
||||||
<category id="selection" label="30012">
|
<category id="selection" label="30012">
|
||||||
|
Loading…
Reference in New Issue
Block a user