mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-17 23:05:11 -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
@ -262,12 +262,15 @@ class SickRage(object):
|
|||||||
os.chdir(sickbeard.DATA_DIR)
|
os.chdir(sickbeard.DATA_DIR)
|
||||||
|
|
||||||
# Check if we need to perform a restore first
|
# Check if we need to perform a restore first
|
||||||
|
try:
|
||||||
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
||||||
if self.consoleLogging and os.path.exists(restoreDir):
|
if self.consoleLogging and os.path.exists(restoreDir):
|
||||||
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
||||||
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
||||||
else:
|
else:
|
||||||
sys.stdout.write("Restore: restoring DB and config.ini FAILED!\n")
|
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
|
# Load the config and publish it to the sickbeard package
|
||||||
if self.consoleLogging and not os.path.isfile(sickbeard.CONFIG_FILE):
|
if self.consoleLogging and not os.path.isfile(sickbeard.CONFIG_FILE):
|
||||||
|
@ -633,8 +633,9 @@ def initialize(consoleLogging=True):
|
|||||||
CACHE_DIR = None
|
CACHE_DIR = None
|
||||||
|
|
||||||
# Check if we need to perform a restore of the cache folder
|
# Check if we need to perform a restore of the cache folder
|
||||||
|
try:
|
||||||
restoreDir = os.path.join(DATA_DIR, 'restore')
|
restoreDir = os.path.join(DATA_DIR, 'restore')
|
||||||
if os.path.exists(restoreDir):
|
if os.path.exists(restoreDir) and os.path.exists(os.path.join(restoreDir, 'cache')):
|
||||||
def restoreCache(srcDir, dstDir):
|
def restoreCache(srcDir, dstDir):
|
||||||
import ntpath
|
import ntpath
|
||||||
import shutil
|
import shutil
|
||||||
@ -651,11 +652,14 @@ def initialize(consoleLogging=True):
|
|||||||
shutil.move(srcDir, dstDir)
|
shutil.move(srcDir, dstDir)
|
||||||
logger.log(u"Restore: restoring cache successful", logger.INFO)
|
logger.log(u"Restore: restoring cache successful", logger.INFO)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log(u"Restore: restoring cache failed", logger.ERROR)
|
logger.log(u"Restore: restoring cache failed: {0}".format(str(e)), logger.ERROR)
|
||||||
finally:
|
|
||||||
os.rmdir(restoreDir)
|
|
||||||
|
|
||||||
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
|
# clean cache folders
|
||||||
if CACHE_DIR:
|
if CACHE_DIR:
|
||||||
|
@ -1080,9 +1080,16 @@ def backupConfigZip(fileList, archive, arcname = None):
|
|||||||
|
|
||||||
|
|
||||||
def restoreConfigZip(archive, targetDir):
|
def restoreConfigZip(archive, targetDir):
|
||||||
|
import ntpath
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(targetDir):
|
if not os.path.exists(targetDir):
|
||||||
os.mkdir(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')
|
zip_file = zipfile.ZipFile(archive, 'r')
|
||||||
for member in zip_file.namelist():
|
for member in zip_file.namelist():
|
||||||
|
Loading…
Reference in New Issue
Block a user