浏览代码

fix: Do partial backups instead of full in trim-database

version-14
Gavin D'souza 3 年前
父节点
当前提交
3734b63c17
共有 2 个文件被更改,包括 26 次插入14 次删除
  1. +24
    -13
      frappe/commands/site.py
  2. +2
    -1
      frappe/utils/backups.py

+ 24
- 13
frappe/commands/site.py 查看文件

@@ -755,7 +755,7 @@ def trim_database(context, dry_run, format, no_backup):
frappe.init(site=site)
frappe.connect()

TABLES_TO_DROPPED = []
TABLES_TO_DROP = []
STANDARD_TABLES = get_standard_tables()
information_schema = frappe.qb.Schema("information_schema")
table_name = frappe.qb.Field("table_name").as_("name")
@@ -772,27 +772,33 @@ def trim_database(context, dry_run, format, no_backup):
for x in database_tables:
doctype = x.lstrip("tab")
if not (doctype in doctype_tables or x.startswith("__") or x in STANDARD_TABLES):
TABLES_TO_DROPPED.append(x)
TABLES_TO_DROP.append(x)

if not TABLES_TO_DROPPED:
if not TABLES_TO_DROP:
if format == "text":
click.secho(f"No ghost tables found in {frappe.local.site}...Great!", fg="green")
else:
if not (no_backup or dry_run):
if format == "text":
click.secho(f"Taking backup for {frappe.local.site}", fg="green")
odb = scheduled_backup(ignore_files=False, force=True)
print(f"Backing Up Tables: {', '.join(TABLES_TO_DROP)}")

odb = scheduled_backup(
ignore_conf=False,
include_doctypes=",".join(x.lstrip("tab") for x in TABLES_TO_DROP),
ignore_files=True,
force=True,
)
if format == "text":
odb.print_summary()
print("\nTrimming Database")

for table in TABLES_TO_DROPPED:
for table in TABLES_TO_DROP:
if format == "text":
print(f"* dropping Table '{table}'...")
print(f"* Dropping Table '{table}'...")
if not dry_run:
frappe.db.sql_ddl(f"drop table `{table}`")

ALL_DATA[frappe.local.site] = TABLES_TO_DROPPED

ALL_DATA[frappe.local.site] = TABLES_TO_DROP
frappe.destroy()

if format == "json":
@@ -802,13 +808,18 @@ def trim_database(context, dry_run, format, no_backup):

def get_standard_tables():
import re

tables = []
sql_file = os.path.join("..", "apps", "frappe", "frappe", "database", frappe.conf.db_type, f'framework_{frappe.conf.db_type}.sql')
sql_file = os.path.join(
"..", "apps", "frappe", "frappe", "database", frappe.conf.db_type, f'framework_{frappe.conf.db_type}.sql'
)
content = open(sql_file).read().splitlines()

for line in content:
beep = re.search("""CREATE TABLE ("|`)(.*)?("|`) \(""", line)
if beep:
tables.append(beep.group(2))
table_found = re.search(r"""CREATE TABLE ("|`)(.*)?("|`) \(""", line)
if table_found:
tables.append(table_found.group(2))

return tables

@click.command('trim-tables')


+ 2
- 1
frappe/utils/backups.py 查看文件

@@ -374,7 +374,8 @@ class BackupGenerator:
backup_info = ("Skipping Tables: ", ", ".join(self.backup_excludes))

if self.partial:
print(''.join(backup_info), "\n")
if self.verbose:
print(''.join(backup_info), "\n")
database_header_content.extend([
f"Partial Backup of Frappe Site {frappe.local.site}",
("Backup contains: " if self.backup_includes else "Backup excludes: ") + backup_info[1],


正在加载...
取消
保存