fix: Add header content in database backups
This commit is contained in:
parent
14fe6ccfa3
commit
2fd5a82bbd
1 changed files with 30 additions and 11 deletions
|
|
@ -342,17 +342,36 @@ class BackupGenerator:
|
|||
|
||||
def take_dump(self):
|
||||
import frappe.utils
|
||||
from frappe.utils.change_log import get_app_branch
|
||||
|
||||
database_header_content = [
|
||||
f"Backup generated by Frappe {frappe.__version__} on branch {get_app_branch('frappe') or 'N/A'}",
|
||||
"",
|
||||
]
|
||||
|
||||
# escape reserved characters
|
||||
args = dict(
|
||||
args = frappe._dict(
|
||||
[item[0], frappe.utils.esc(str(item[1]), "$ ")]
|
||||
for item in self.__dict__.copy().items()
|
||||
)
|
||||
|
||||
if self.backup_includes:
|
||||
print("Backing Up Tables: {0}\n".format(", ".join(self.backup_includes)))
|
||||
backup_info = ("Backing Up Tables: ", ", ".join(self.backup_includes))
|
||||
elif self.backup_excludes:
|
||||
print("Skipping Tables: {0}\n".format(", ".join(self.backup_excludes)))
|
||||
backup_info = ("Skipping Tables: ", ", ".join(self.backup_excludes))
|
||||
|
||||
if self.partial:
|
||||
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],
|
||||
"",
|
||||
])
|
||||
|
||||
generated_header = "\n".join([f"-- {x}" for x in database_header_content]) + "\n"
|
||||
|
||||
with gzip.open(args.backup_path_db, "wt") as f:
|
||||
f.write(generated_header)
|
||||
|
||||
if self.db_type == "postgres":
|
||||
if self.backup_includes:
|
||||
|
|
@ -366,7 +385,7 @@ class BackupGenerator:
|
|||
|
||||
cmd_string = (
|
||||
"pg_dump postgres://{user}:{password}@{db_host}:{db_port}/{db_name}"
|
||||
" {include} {exclude} | gzip > {backup_path_db}"
|
||||
" {include} {exclude} | gzip >> {backup_path_db}"
|
||||
)
|
||||
|
||||
else:
|
||||
|
|
@ -383,16 +402,16 @@ class BackupGenerator:
|
|||
cmd_string = (
|
||||
"mysqldump --single-transaction --quick --lock-tables=false -u {user}"
|
||||
" -p{password} {db_name} -h {db_host} -P {db_port} {include} {exclude}"
|
||||
" | gzip > {backup_path_db}"
|
||||
" | gzip >> {backup_path_db}"
|
||||
)
|
||||
|
||||
command = cmd_string.format(
|
||||
user=args.get("user"),
|
||||
password=args.get("password"),
|
||||
db_host=args.get("db_host"),
|
||||
db_port=args.get("db_port"),
|
||||
db_name=args.get("db_name"),
|
||||
backup_path_db=args.get("backup_path_db"),
|
||||
user=args.user,
|
||||
password=args.password,
|
||||
db_host=args.db_host,
|
||||
db_port=args.db_port,
|
||||
db_name=args.db_name,
|
||||
backup_path_db=args.backup_path_db,
|
||||
exclude=args.get("exclude", ""),
|
||||
include=args.get("include", ""),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue