Commit 3151280c authored by echel0n's avatar echel0n

Cleaned up backup and restore functions for database.

Bumped keycloak requirement to v0.2.2
parent fe70b173
# Changelog
- * d2e85f8 - 2019-03-03: Added backup and restore functions to database class. Refactored backup and restore system for app to accommodate for migration to python 3.
- * db4354e - 2019-03-04: Cleaned up backup and restore functions for database. Bumped keycloak requirement to v0.2.2
- * fe70b17 - 2019-03-03: Added backup and restore functions to database class. Refactored backup and restore system for app to accommodate for migration to python 3.
- * a72ca25 - 2019-02-24: Release v9.4.77
- * b09d78a - 2019-02-24: Added Anime regex for Erai-raws
- * e0f2db6 - 2019-02-24: Release v9.4.76
......
......@@ -41,7 +41,7 @@ chardet == 3.0.4
pytz == 2018.7
tzlocal == 2.0.0b1
raven == 6.9.0
python-keycloak-client == 0.2.1
python-keycloak-client == 0.2.2
simplejson == 3.16.0
service_identity == 17.0.0
certifi
......
......@@ -60,12 +60,14 @@ class srDatabase(object):
def initialize(self):
# Remove database folder if both exists
if self.db.exists() and os.path.isfile(self.old_db_path):
self.db.open()
if not self.opened:
self.db.open()
self.db.destroy()
if self.db.exists():
# self.backup()
self.db.open()
if not self.opened:
self.db.open()
else:
self.db.create()
......@@ -402,7 +404,6 @@ class srDatabase(object):
continue
def backup(self, backup_file=None):
backup_file = backup_file or os.path.join(sickrage.app.data_dir, '{}_db.pickle'.format(self.name))
sickrage.app.log.info('Backing up {} database to {}'.format(self.name, backup_file))
with io.open(backup_file, 'wb') as f:
rows = []
......@@ -420,8 +421,7 @@ class srDatabase(object):
return backup_file
def restore(self):
restore_file = os.path.join(sickrage.app.data_dir, 'restore', '{}_db.pickle'.format(self.name))
def restore(self, restore_file=None):
backup_file = os.path.join(sickrage.app.data_dir, '{}_db.pickle.bak-{}'.format(self.name,
datetime.datetime.now().strftime(
'%Y%m%d_%H%M%S')))
......@@ -431,6 +431,9 @@ class srDatabase(object):
with io.open(restore_file, 'rb') as f:
rows = pickle.load(f)
if not self.opened:
self.db.open()
self.db.destroy()
self.db.create()
[self.insert(row) for row in rows]
......
......@@ -1028,7 +1028,7 @@ def backupSR(backupDir, keep_latest=False, migrate=True):
# database
for db in [sickrage.app.main_db, sickrage.app.cache_db]:
backup_file = db.backup()
backup_file = db.backup(os.path.join(sickrage.app.data_dir, '{}_db.pickle'.format(db.name)))
source += [backup_file]
# cache folder
......@@ -1068,9 +1068,9 @@ def restoreSR(srcDir, dstDir):
# database
for db in [sickrage.app.main_db, sickrage.app.cache_db]:
db.initialize()
db.restore()
db.close()
restore_file = os.path.join(sickrage.app.data_dir, 'restore', '{}_db.pickle'.format(db.name))
if os.path.exists(restore_file):
db.restore(restore_file)
# cache
if os.path.exists(os.path.join(srcDir, 'cache')):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment