mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-11 13:58:31 -05:00
Merge pull request #1358 from abeloin/patch-backup_fixes
Fix backup issue with invalid restore folder
This commit is contained in:
commit
699d9270fb
15
SickBeard.py
15
SickBeard.py
@ -262,12 +262,15 @@ class SickRage(object):
|
||||
os.chdir(sickbeard.DATA_DIR)
|
||||
|
||||
# Check if we need to perform a restore first
|
||||
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
||||
if self.consoleLogging and os.path.exists(restoreDir):
|
||||
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
||||
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
||||
else:
|
||||
sys.stdout.write("Restore: restoring DB and config.ini FAILED!\n")
|
||||
try:
|
||||
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
||||
if self.consoleLogging and os.path.exists(restoreDir):
|
||||
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
||||
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
||||
else:
|
||||
sys.stdout.write("Restore: restoring DB and config.ini FAILED!\n")
|
||||
except Exception as e:
|
||||
sys.stdout.write("Restore: restoring DB and config.ini FAILED!\n")
|
||||
|
||||
# Load the config and publish it to the sickbeard package
|
||||
if self.consoleLogging and not os.path.isfile(sickbeard.CONFIG_FILE):
|
||||
|
@ -633,29 +633,33 @@ def initialize(consoleLogging=True):
|
||||
CACHE_DIR = None
|
||||
|
||||
# Check if we need to perform a restore of the cache folder
|
||||
restoreDir = os.path.join(DATA_DIR, 'restore')
|
||||
if os.path.exists(restoreDir):
|
||||
def restoreCache(srcDir, dstDir):
|
||||
import ntpath
|
||||
import shutil
|
||||
try:
|
||||
restoreDir = os.path.join(DATA_DIR, 'restore')
|
||||
if os.path.exists(restoreDir) and os.path.exists(os.path.join(restoreDir, 'cache')):
|
||||
def restoreCache(srcDir, dstDir):
|
||||
import ntpath
|
||||
import shutil
|
||||
|
||||
def path_leaf(path):
|
||||
head, tail = ntpath.split(path)
|
||||
return tail or ntpath.basename(head)
|
||||
def path_leaf(path):
|
||||
head, tail = ntpath.split(path)
|
||||
return tail or ntpath.basename(head)
|
||||
|
||||
try:
|
||||
if os.path.isdir(dstDir):
|
||||
bakFilename = '{0}-{1}'.format(path_leaf(dstDir), datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d_%H%M%S'))
|
||||
shutil.move(dstDir, os.path.join(ntpath.dirname(dstDir), bakFilename))
|
||||
try:
|
||||
if os.path.isdir(dstDir):
|
||||
bakFilename = '{0}-{1}'.format(path_leaf(dstDir), datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d_%H%M%S'))
|
||||
shutil.move(dstDir, os.path.join(ntpath.dirname(dstDir), bakFilename))
|
||||
|
||||
shutil.move(srcDir, dstDir)
|
||||
logger.log(u"Restore: restoring cache successful", logger.INFO)
|
||||
except Exception as e:
|
||||
logger.log(u"Restore: restoring cache failed", logger.ERROR)
|
||||
finally:
|
||||
os.rmdir(restoreDir)
|
||||
shutil.move(srcDir, dstDir)
|
||||
logger.log(u"Restore: restoring cache successful", logger.INFO)
|
||||
except Exception as e:
|
||||
logger.log(u"Restore: restoring cache failed: {0}".format(str(e)), logger.ERROR)
|
||||
|
||||
restoreCache(os.path.join(restoreDir, 'cache'), CACHE_DIR)
|
||||
restoreCache(os.path.join(restoreDir, 'cache'), CACHE_DIR)
|
||||
except Exception as e:
|
||||
logger.log(u"Restore: restoring cache failed: {0}".format(str(e)), logger.ERROR)
|
||||
finally:
|
||||
if os.path.exists(os.path.join(DATA_DIR, 'restore')):
|
||||
os.rmdir(os.path.join(DATA_DIR, 'restore'))
|
||||
|
||||
# clean cache folders
|
||||
if CACHE_DIR:
|
||||
|
@ -1080,9 +1080,16 @@ def backupConfigZip(fileList, archive, arcname = None):
|
||||
|
||||
|
||||
def restoreConfigZip(archive, targetDir):
|
||||
import ntpath
|
||||
try:
|
||||
if not os.path.exists(targetDir):
|
||||
os.mkdir(targetDir)
|
||||
else:
|
||||
def path_leaf(path):
|
||||
head, tail = ntpath.split(path)
|
||||
return tail or ntpath.basename(head)
|
||||
bakFilename = '{0}-{1}'.format(path_leaf(targetDir), datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d_%H%M%S'))
|
||||
shutil.move(targetDir, os.path.join(ntpath.dirname(targetDir), bakFilename))
|
||||
|
||||
zip_file = zipfile.ZipFile(archive, 'r')
|
||||
for member in zip_file.namelist():
|
||||
|
Loading…
Reference in New Issue
Block a user