fix: always take a fresh backup before uploading to S3 - #28
Closed
iamimmanuelraj wants to merge 3 commits into
Closed
fix: always take a fresh backup before uploading to S3#28iamimmanuelraj wants to merge 3 commits into
iamimmanuelraj wants to merge 3 commits into
Conversation
backup_to_s3() reuses on-disk backups when create_new_backup is False (large DBs). get_recent_backup() returns None for the site config when no site_config_backup file exists on disk, so upload_file_to_s3(site_config) crashes with 'expected str, bytes or os.PathLike object, not NoneType' and only the database file gets uploaded. Regenerate the site config via BackupGenerator.copy_site_config() when it is missing, so the config is always uploaded alongside the database.
backup_to_s3() reused existing on-disk backups when the db dump exceeded 1GB
(via validate_file_size / create_new_backup). That reuse path selected the
newest file of each type independently, so it could stitch a db and files from
different runs, and get_recent_backup() returned None for the site config when
no site_config_backup file was present on disk, crashing the upload:
upload_file_to_s3(site_config, ...) # os.path.basename(None) -> TypeError
leaving only the database uploaded and emailing 'Backup Upload Failed'.
Always call new_backup(force=True) so db, site config and (optionally) files
come from one consistent run. Removes the size check and reuse path;
ignore_files mirrors the 'Backup Files' setting.
Note: dumps the full database on every run.
After a successful offsite upload, call delete_temp_backups() so the fresh full backups produced each run don't accumulate on disk. Deletes local backup files older than keep_backups_for_hours; does not affect what was just uploaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the database dump exceeds 1GB,
validate_file_size()setsfrappe.flags.create_new_backup = False, sobackup_to_s3()skipsnew_backup()and reuses whatever backup files are already on disk.That reuse path is broken:
get_recent_backup()picks the newest file of each type independently, so the db and files can come from different backup runs.Nonefor the site config whenever no*-site_config_backup.jsonis present on disk. On Frappe Cloud the local config gets removed by the offsite agent after upload (frappe/agentSite.upload_offsite_backup), so this happens routinely.The next line then crashes:
Result: only the database file lands in S3, then the job dies and the user gets a "Backup Upload Failed" email even though a backup exists.
Fix
Always call
new_backup(force=True)inbackup_to_s3(). The db, site config, and (optionally) files then always come from one consistent run and the config is guaranteed to exist. This removes thevalidate_file_sizesize check and the entire reuse path;ignore_filesmirrors the existing "Backup Files" setting.Note
This dumps the full database on every scheduled run (which is the intended behaviour for an offsite backup). The previous size-based reuse was what produced inconsistent, partial uploads.