Skip to content

Commit

Permalink
refactor(physical-backup): Store checksum and size of file during backup
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Jan 23, 2025
1 parent 2772644 commit 33a082e
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 3 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2025, Frappe and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Physical Backup File Metadata", {
// refresh(frm) {

// },
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2025-01-23 19:06:50.174314",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"file",
"size",
"checksum"
],
"fields": [
{
"fieldname": "checksum",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Checksum",
"read_only": 1
},
{
"fieldname": "size",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Size",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "file",
"fieldtype": "Data",
"in_list_view": 1,
"label": "File",
"read_only": 1,
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2025-01-23 19:23:33.543343",
"modified_by": "Administrator",
"module": "Press",
"name": "Physical Backup File Metadata",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

# Copyright (c) 2025, Frappe and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document


class PhysicalBackupFileMetadata(Document):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from frappe.types import DF

checksum: DF.Data | None
file: DF.Data
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
size: DF.Int
# end: auto-generated types

pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2025, Frappe and Contributors
# See license.txt

# import frappe
from frappe.tests import IntegrationTestCase, UnitTestCase

# On IntegrationTestCase, the doctype test records and all
# link-field test record depdendencies are recursively loaded
# Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]


class UnitTestPhysicalBackupFileMetadata(UnitTestCase):
"""
Unit tests for PhysicalBackupFileMetadata.
Use this class for testing individual functions and methods.
"""

pass


class IntegrationTestPhysicalBackupFileMetadata(IntegrationTestCase):
"""
Integration tests for PhysicalBackupFileMetadata.
Use this class for testing interactions between multiple components.
"""

pass
15 changes: 12 additions & 3 deletions press/press/doctype/site_backup/site_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
"column_break_hksx",
"snapshot_request_key",
"section_break_ujrn",
"table_schema",
"files_metadata",
"innodb_tables",
"myisam_tables",
"table_schema"
"myisam_tables"
],
"fields": [
{
Expand Down Expand Up @@ -77,6 +78,7 @@
},
{
"default": "0",
"depends_on": "eval: doc.physical != 1",
"fieldname": "with_files",
"fieldtype": "Check",
"in_list_view": 1,
Expand Down Expand Up @@ -154,6 +156,7 @@
},
{
"default": "0",
"depends_on": "eval: doc.physical != 1",
"fieldname": "offsite",
"fieldtype": "Check",
"in_list_view": 1,
Expand Down Expand Up @@ -308,10 +311,16 @@
{
"fieldname": "column_break_obsx",
"fieldtype": "Column Break"
},
{
"fieldname": "files_metadata",
"fieldtype": "Table",
"label": "Files Metadata",
"options": "Physical Backup File Metadata"
}
],
"links": [],
"modified": "2025-01-17 16:44:02.263787",
"modified": "2025-01-23 19:17:18.638961",
"modified_by": "Administrator",
"module": "Press",
"name": "Site Backup",
Expand Down
19 changes: 19 additions & 0 deletions press/press/doctype/site_backup/site_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class SiteBackup(Document):
if TYPE_CHECKING:
from frappe.types import DF

from press.press.doctype.physical_backup_file_metadata.physical_backup_file_metadata import (
PhysicalBackupFileMetadata,
)

config_file: DF.Data | None
config_file_size: DF.Data | None
config_file_url: DF.Text | None
Expand All @@ -35,6 +39,7 @@ class SiteBackup(Document):
database_snapshot: DF.Link | None
database_url: DF.Text | None
files_availability: DF.Literal["", "Available", "Unavailable"]
files_metadata: DF.Table[PhysicalBackupFileMetadata]
innodb_tables: DF.JSON | None
job: DF.Link | None
myisam_tables: DF.JSON | None
Expand Down Expand Up @@ -290,6 +295,16 @@ def process_backup_site_job_update(job): # noqa: C901
site_backup.innodb_tables = json.dumps(data[site_backup.database_name]["innodb_tables"])
site_backup.myisam_tables = json.dumps(data[site_backup.database_name]["myisam_tables"])
site_backup.table_schema = data[site_backup.database_name]["table_schema"]
files_metadata = data[site_backup.database_name]["files_metadata"]
for x in files_metadata:
site_backup.append(

Check warning on line 300 in press/press/doctype/site_backup/site_backup.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/site_backup/site_backup.py#L294-L300

Added lines #L294 - L300 were not covered by tests
"files_metadata",
{
"file": x,
"size": files_metadata[x]["size"],
"checksum": files_metadata[x]["checksum"],
},
)
site_backup.status = "Success"
site_backup.save()
site_backup.reload()

Check warning on line 310 in press/press/doctype/site_backup/site_backup.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/site_backup/site_backup.py#L308-L310

Added lines #L308 - L310 were not covered by tests
Expand Down Expand Up @@ -343,6 +358,10 @@ def process_backup_site_job_update(job): # noqa: C901
)

frappe.db.set_value("Site Backup", backup.name, site_backup_dict)
else:
site_backup: SiteBackup = frappe.get_doc("Site Backup", backup.name)
site_backup.status = status
site_backup.save()

Check warning on line 364 in press/press/doctype/site_backup/site_backup.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/site_backup/site_backup.py#L362-L364

Added lines #L362 - L364 were not covered by tests


def get_backup_bucket(cluster, region=False):
Expand Down

0 comments on commit 33a082e

Please sign in to comment.