mirror of
https://github.com/borgbase/vorta
synced 2024-12-21 23:33:13 +00:00
Backup settings.db before migrations. By @AdwaitSalankar (#1848)
This commit is contained in:
parent
98b64621c2
commit
c9f170aecf
1 changed files with 13 additions and 0 deletions
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
import shutil
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from peewee import Tuple, fn
|
||||
from playhouse import signals
|
||||
|
||||
from vorta import config
|
||||
from vorta.autostart import open_app_at_startup
|
||||
|
||||
from .migrations import run_migrations
|
||||
|
@ -83,6 +85,7 @@ def init_db(con=None):
|
|||
if created or current_schema.version == SCHEMA_VERSION:
|
||||
pass
|
||||
else:
|
||||
backup_current_db(current_schema.version)
|
||||
run_migrations(current_schema, con)
|
||||
|
||||
# Create missing settings and update labels.
|
||||
|
@ -98,3 +101,13 @@ def init_db(con=None):
|
|||
s.tooltip = setting['tooltip']
|
||||
|
||||
s.save()
|
||||
|
||||
|
||||
def backup_current_db(schema_version):
|
||||
"""
|
||||
Creates a backup copy of settings.db
|
||||
"""
|
||||
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
|
||||
backup_file_name = f'settings_v{schema_version}_{timestamp}.db'
|
||||
shutil.copy(config.SETTINGS_DIR / 'settings.db', config.SETTINGS_DIR / backup_file_name)
|
||||
|
|
Loading…
Reference in a new issue