feat: ignore tar: file changed as we read it during backups
This seems to occur when new files are being created as we're archiving the files on a site. Doesn't make sense to fail the entire backup because of that. Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
803f7b3990
commit
803b45b9fa
3 changed files with 23 additions and 7 deletions
|
|
@ -300,3 +300,10 @@ class InvalidKeyError(ValidationError):
|
|||
http_status_code = 401
|
||||
title = "Invalid Key"
|
||||
message = "The document key is invalid"
|
||||
|
||||
|
||||
class CommandFailedError(Exception):
|
||||
def __init__(self, message: str, out: str, err: str):
|
||||
super().__init__(message)
|
||||
self.out = out
|
||||
self.err = err
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ def execute_in_shell(cmd, verbose=False, low_priority=False, check_exit_code=Fal
|
|||
print(out)
|
||||
|
||||
if failed:
|
||||
raise Exception("Command failed")
|
||||
raise frappe.CommandFailedError("Command failed", out.decode(), err.decode())
|
||||
|
||||
return err, out
|
||||
|
||||
|
|
|
|||
|
|
@ -352,12 +352,21 @@ class BackupGenerator:
|
|||
else:
|
||||
cmd_string = "tar -cf {0} {1}"
|
||||
|
||||
frappe.utils.execute_in_shell(
|
||||
cmd_string.format(backup_path, files_path),
|
||||
verbose=self.verbose,
|
||||
low_priority=True,
|
||||
check_exit_code=True,
|
||||
)
|
||||
try:
|
||||
frappe.utils.execute_in_shell(
|
||||
cmd_string.format(backup_path, files_path),
|
||||
verbose=self.verbose,
|
||||
low_priority=True,
|
||||
check_exit_code=True,
|
||||
)
|
||||
except frappe.CommandFailedError as e:
|
||||
if e.err and "file changed as we read it" in e.err:
|
||||
click.secho(
|
||||
"Ignoring `tar: file changed as we read it` to prevent backup failure",
|
||||
fg="red",
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
|
||||
def copy_site_config(self):
|
||||
site_config_backup_path = self.backup_path_conf
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue