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:
Akhil Narang 2024-05-17 11:39:41 +05:30
parent 803f7b3990
commit 803b45b9fa
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F
3 changed files with 23 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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