1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-01-03 05:36:19 +00:00

Backup settings.db before migrations. By @AdwaitSalankar (#1848)

This commit is contained in:
Adwait 2023-11-24 20:59:28 +05:30 committed by GitHub
parent 98b64621c2
commit c9f170aecf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,11 @@
import os import os
import shutil
from datetime import datetime, timedelta from datetime import datetime, timedelta
from peewee import Tuple, fn from peewee import Tuple, fn
from playhouse import signals from playhouse import signals
from vorta import config
from vorta.autostart import open_app_at_startup from vorta.autostart import open_app_at_startup
from .migrations import run_migrations from .migrations import run_migrations
@ -83,6 +85,7 @@ def init_db(con=None):
if created or current_schema.version == SCHEMA_VERSION: if created or current_schema.version == SCHEMA_VERSION:
pass pass
else: else:
backup_current_db(current_schema.version)
run_migrations(current_schema, con) run_migrations(current_schema, con)
# Create missing settings and update labels. # Create missing settings and update labels.
@ -98,3 +101,13 @@ def init_db(con=None):
s.tooltip = setting['tooltip'] s.tooltip = setting['tooltip']
s.save() 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)