mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Set backups to live in a directory with the backup id
This commit is contained in:
parent
a69d569e23
commit
8dd82f4111
@ -1150,6 +1150,9 @@ class ServerInstance:
|
||||
)
|
||||
time.sleep(3)
|
||||
conf = HelpersManagement.get_backup_config(backup_id)
|
||||
conf["backup_location"] = os.path.join(
|
||||
conf["backup_location"], conf["backup_id"]
|
||||
)
|
||||
backup_location = conf["backup_location"]
|
||||
if not backup_location:
|
||||
Console.critical("No backup path found. Canceling")
|
||||
@ -1201,10 +1204,10 @@ class ServerInstance:
|
||||
)
|
||||
|
||||
while (
|
||||
len(self.list_backups(backup_location)) > conf["max_backups"]
|
||||
len(self.list_backups(conf)) > conf["max_backups"]
|
||||
and conf["max_backups"] > 0
|
||||
):
|
||||
backup_list = self.list_backups(conf["backup_location"])
|
||||
backup_list = self.list_backups(conf)
|
||||
oldfile = backup_list[0]
|
||||
oldfile_path = f"{backup_location}/{oldfile['path']}"
|
||||
logger.info(f"Removing old backup '{oldfile['path']}'")
|
||||
@ -1292,12 +1295,15 @@ class ServerInstance:
|
||||
alert = True
|
||||
self.last_backup_failed = alert
|
||||
|
||||
def list_backups(self, backup_location):
|
||||
if not backup_location:
|
||||
def list_backups(self, backup_config: dict) -> list:
|
||||
if not backup_config:
|
||||
logger.info(
|
||||
f"Error putting backup file list for server with ID: {self.server_id}"
|
||||
)
|
||||
return []
|
||||
backup_location = os.path.join(
|
||||
backup_config["backup_location"], backup_config["backup_id"]
|
||||
)
|
||||
if not Helpers.check_path_exists(
|
||||
Helpers.get_os_understandable_path(backup_location)
|
||||
):
|
||||
|
@ -1289,7 +1289,7 @@ class PanelHandler(BaseHandler):
|
||||
self.controller.servers.refresh_server_settings(server_id)
|
||||
try:
|
||||
page_data["backup_list"] = server.list_backups(
|
||||
page_data["backup_config"]["backup_location"]
|
||||
page_data["backup_config"]
|
||||
)
|
||||
except:
|
||||
page_data["backup_list"] = []
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import datetime
|
||||
import uuid
|
||||
import peewee
|
||||
@ -8,6 +9,7 @@ from app.classes.models.management import Backups, Schedules
|
||||
from app.classes.shared.helpers import Helpers
|
||||
from app.classes.shared.console import Console
|
||||
from app.classes.shared.migration import Migrator, MigrateHistory
|
||||
from app.classes.shared.file_helpers import FileHelpers
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -116,7 +118,7 @@ def migrate(migrator: Migrator, database, **kwargs):
|
||||
Console.info(f"Migrations: Migrating backup for server {server.server_name}")
|
||||
# Create a new backup entry with data from the
|
||||
# old backup entry and related server
|
||||
NewBackups.create(
|
||||
new_backup = NewBackups.create(
|
||||
backup_name=f"{server.server_name} Backup",
|
||||
# Set backup_location equal to backup_path
|
||||
backup_location=server.backup_path,
|
||||
@ -130,6 +132,15 @@ def migrate(migrator: Migrator, database, **kwargs):
|
||||
default=True,
|
||||
enabled=True,
|
||||
)
|
||||
Helpers.ensure_dir_exists(
|
||||
os.path.join(server.backup_path, new_backup.backup_id)
|
||||
)
|
||||
for file in os.listdir(server.backup_path):
|
||||
if not os.path.isdir(os.path.join(os.path.join(server.backup_path, file))):
|
||||
FileHelpers.move_file(
|
||||
os.path.join(server.backup_path, file),
|
||||
os.path.join(server.backup_path, new_backup.backup_id, file),
|
||||
)
|
||||
|
||||
Console.debug("Migrations: Dropping old backup table")
|
||||
# Drop the existing backups table
|
||||
|
Loading…
Reference in New Issue
Block a user