add archive to keep databases permanently stored in an archive folder
This commit is contained in:
@@ -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