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
15
SickBeard.py
15
SickBeard.py
@ -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
|
||||||
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
try:
|
||||||
if self.consoleLogging and os.path.exists(restoreDir):
|
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
||||||
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
if self.consoleLogging and os.path.exists(restoreDir):
|
||||||
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
if self.restoreDB(restoreDir, sickbeard.DATA_DIR):
|
||||||
else:
|
sys.stdout.write("Restore: restoring DB and config.ini successful...\n")
|
||||||
sys.stdout.write("Restore: restoring DB and config.ini FAILED!\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
|
# 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,29 +633,33 @@ 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
|
||||||
restoreDir = os.path.join(DATA_DIR, 'restore')
|
try:
|
||||||
if os.path.exists(restoreDir):
|
restoreDir = os.path.join(DATA_DIR, 'restore')
|
||||||
def restoreCache(srcDir, dstDir):
|
if os.path.exists(restoreDir) and os.path.exists(os.path.join(restoreDir, 'cache')):
|
||||||
import ntpath
|
def restoreCache(srcDir, dstDir):
|
||||||
import shutil
|
import ntpath
|
||||||
|
import shutil
|
||||||
|
|
||||||
def path_leaf(path):
|
def path_leaf(path):
|
||||||
head, tail = ntpath.split(path)
|
head, tail = ntpath.split(path)
|
||||||
return tail or ntpath.basename(head)
|
return tail or ntpath.basename(head)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os.path.isdir(dstDir):
|
if os.path.isdir(dstDir):
|
||||||
bakFilename = '{0}-{1}'.format(path_leaf(dstDir), datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d_%H%M%S'))
|
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(dstDir, os.path.join(ntpath.dirname(dstDir), bakFilename))
|
||||||
|
|
||||||
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