add archive to keep databases permanently stored in an archive folder
This commit is contained in:
@@ -9,3 +9,7 @@ Bei jedem Schließen der Anwendung wird ein Backup der Datenbank erstellt. Diese
|
||||
Sollte der normale Speicherpfad nicht existieren oder nicht erreichbar sein (im Falle eines Netzwerklaufwerks), wird der Backuppfad verwendet. Beim Schließen der Anwendung wird ein Fehler angezeigt, dass das Erstellen des Backups nicht erfolgreich war. Solange der originale Pfad nicht erreichbar ist, wird der Backuppfad verwendet.
|
||||
|
||||
Sobald der originale Pfad wieder erreichbar ist, wird die Datenbank in den originalen Pfad kopiert, die veraltete Datenbank wird gelöscht und der Backuppfad wird wieder verwendet.
|
||||
|
||||
## Datenbankarchiv
|
||||
|
||||
Um eventuelle Datenbeschädigungen zu vermeiden, wird die Datenbank bei jedem Beenden der Anwendung in ein Archiv kopiert. Dieses Archiv wird im Archivpfad gespeichert, der Archivpfad nutzt den Sicherungspfad als grundlage und erstellt einen neuen Ordner "archive" in diesem Pfad.
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import sys
|
||||
import shutil
|
||||
from src import config
|
||||
|
||||
import datetime
|
||||
|
||||
class Backup:
|
||||
def __init__(self):
|
||||
@@ -11,6 +11,15 @@ class Backup:
|
||||
self.backup = False
|
||||
if not os.path.exists(config.database.backupLocation):
|
||||
os.makedirs(config.database.backupLocation)
|
||||
backupPath = config.database.backupLocation
|
||||
# create an archive path based on the backuppath, one level up with a new folder called archive
|
||||
# example: backuppath = /home/user/backup
|
||||
# result: archivepath = /home/user/archive
|
||||
self.archivePath = os.path.join(os.path.dirname(backupPath), "archive")
|
||||
# check if the archive path exists, if not create it
|
||||
if not os.path.exists(self.archivePath):
|
||||
os.makedirs(self.archivePath)
|
||||
|
||||
if config.database.do_backup == True:
|
||||
self.checkpaths()
|
||||
config.database.do_backup = self.backup
|
||||
@@ -20,6 +29,17 @@ class Backup:
|
||||
self.backup = True
|
||||
|
||||
def createBackup(self):
|
||||
if os.path.exists(self.archivePath):
|
||||
# copy the active database to the archive path, add _[date]
|
||||
day = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
# copy the active database to the archive path, add _[date]
|
||||
shutil.copy(
|
||||
self.source_path,
|
||||
os.path.join(
|
||||
self.archivePath, config.database.name + "_" + day + ".archive"
|
||||
),
|
||||
)
|
||||
|
||||
if self.backup:
|
||||
if os.path.exists(self.source_path):
|
||||
if os.path.exists(self.backup_path):
|
||||
|
||||
Reference in New Issue
Block a user