diff --git a/frappe/integrations/doctype/dropbox_settings/dropbox_settings.py b/frappe/integrations/doctype/dropbox_settings/dropbox_settings.py index f177aa6620..864720174f 100644 --- a/frappe/integrations/doctype/dropbox_settings/dropbox_settings.py +++ b/frappe/integrations/doctype/dropbox_settings/dropbox_settings.py @@ -97,10 +97,12 @@ def backup_to_dropbox(upload_db_backup=True): if frappe.flags.create_new_backup: backup = new_backup(ignore_files=True) filename = os.path.join(get_backups_path(), os.path.basename(backup.backup_path_db)) + site_config = os.path.join(get_backups_path(), os.path.basename(backup.site_config_backup_path)) else: - filename = get_latest_backup_file() + filename, site_config = get_latest_backup_file() upload_file_to_dropbox(filename, "/database", dropbox_client) + upload_file_to_dropbox(site_config, "/database", dropbox_client) # delete older databases if dropbox_settings['no_of_backups']: diff --git a/frappe/integrations/doctype/google_drive/google_drive.py b/frappe/integrations/doctype/google_drive/google_drive.py index 60ee173bbf..46e3235c15 100644 --- a/frappe/integrations/doctype/google_drive/google_drive.py +++ b/frappe/integrations/doctype/google_drive/google_drive.py @@ -190,12 +190,13 @@ def upload_system_backup_to_google_drive(): set_progress(1, "Backing up Data.") backup = new_backup() fileurl_backup = os.path.basename(backup.backup_path_db) + fileurl_site_config = os.path.basename(backup.site_config_backup_path) fileurl_public_files = os.path.basename(backup.backup_path_files) fileurl_private_files = os.path.basename(backup.backup_path_private_files) else: - fileurl_backup, fileurl_public_files, fileurl_private_files = get_latest_backup_file(with_files=True) + fileurl_backup, fileurl_site_config, fileurl_public_files, fileurl_private_files = get_latest_backup_file(with_files=True) - for fileurl in [fileurl_backup, fileurl_public_files, fileurl_private_files]: + for fileurl in [fileurl_backup, fileurl_site_config, fileurl_public_files, fileurl_private_files]: file_metadata = { "name": fileurl, "parents": [account.backup_folder_id] diff --git a/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.py b/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.py index 21232992f4..6cfd3646b2 100755 --- a/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.py +++ b/frappe/integrations/doctype/s3_backup_settings/s3_backup_settings.py @@ -115,19 +115,21 @@ def backup_to_s3(): backup = new_backup(ignore_files=False, backup_path_db=None, backup_path_files=None, backup_path_private_files=None, force=True) db_filename = os.path.join(get_backups_path(), os.path.basename(backup.backup_path_db)) + site_config = os.path.join(get_backups_path(), os.path.basename(backup.site_config_backup_path)) if backup_files: files_filename = os.path.join(get_backups_path(), os.path.basename(backup.backup_path_files)) private_files = os.path.join(get_backups_path(), os.path.basename(backup.backup_path_private_files)) else: if backup_files: - db_filename, files_filename, private_files = get_latest_backup_file(with_files=backup_files) + db_filename, site_config, files_filename, private_files = get_latest_backup_file(with_files=backup_files) else: - db_filename = get_latest_backup_file() + db_filename, site_config = get_latest_backup_file() folder = os.path.basename(db_filename)[:15] + '/' # for adding datetime to folder name upload_file_to_s3(db_filename, folder, conn, bucket) + upload_file_to_s3(site_config, folder, conn, bucket) if backup_files: upload_file_to_s3(private_files, folder, conn, bucket) upload_file_to_s3(files_filename, folder, conn, bucket) diff --git a/frappe/integrations/offsite_backup_utils.py b/frappe/integrations/offsite_backup_utils.py index 7e80cb68c4..a47933f68e 100644 --- a/frappe/integrations/offsite_backup_utils.py +++ b/frappe/integrations/offsite_backup_utils.py @@ -50,13 +50,14 @@ def get_latest_backup_file(with_files=False): return max(file_list, key=os.path.getctime) latest_file = get_latest('*.sql.gz') + latest_site_config = get_latest('*.json') if with_files: latest_public_file_bak = get_latest('*-files.tar') latest_private_file_bak = get_latest('*-private-files.tar') - return latest_file, latest_public_file_bak, latest_private_file_bak + return latest_file, latest_site_config, latest_public_file_bak, latest_private_file_bak - return latest_file + return latest_file, latest_site_config def get_file_size(file_path, unit): @@ -76,7 +77,7 @@ def get_file_size(file_path, unit): def validate_file_size(): frappe.flags.create_new_backup = True - latest_file = get_latest_backup_file() + latest_file, site_config = get_latest_backup_file() file_size = get_file_size(latest_file, unit='GB') if file_size > 1: diff --git a/frappe/utils/backups.py b/frappe/utils/backups.py index e4e9b65e49..b17ce0e1be 100644 --- a/frappe/utils/backups.py +++ b/frappe/utils/backups.py @@ -6,6 +6,7 @@ from __future__ import print_function, unicode_literals import os +import json from datetime import datetime import frappe @@ -46,15 +47,16 @@ class BackupGenerator: #Check if file exists and is less than a day old #If not Take Dump if not force: - last_db, last_file, last_private_file = self.get_recent_backup(older_than) + last_db, last_file, last_private_file, site_config_backup_path = self.get_recent_backup(older_than) else: - last_db, last_file, last_private_file = False, False, False + last_db, last_file, last_private_file, site_config_backup_path = False, False, False, False if not (self.backup_path_files and self.backup_path_db and self.backup_path_private_files): self.set_backup_file_name() - if not (last_db and last_file and last_private_file): + if not (last_db and last_file and last_private_file and site_config_backup_path): self.take_dump() + self.copy_site_config() if not ignore_files: self.zip_files() @@ -62,6 +64,7 @@ class BackupGenerator: self.backup_path_files = last_file self.backup_path_db = last_db self.backup_path_private_files = last_private_file + self.site_config_backup_path = site_config_backup_path def set_backup_file_name(self): todays_date = now_datetime().strftime('%Y%m%d_%H%M%S') @@ -97,8 +100,10 @@ class BackupGenerator: backup_path_files = this_file_path elif "_database" in this_file_path: backup_path_db = this_file_path + elif "site_config" in this_file_path: + site_config_backup_path = this_file_path - return (backup_path_db, backup_path_files, backup_path_private_files) + return (backup_path_db, backup_path_files, backup_path_private_files, site_config_backup_path) def zip_files(self): for folder in ("public", "private"): @@ -111,6 +116,18 @@ class BackupGenerator: if self.verbose: print('Backed up files', os.path.abspath(backup_path)) + def copy_site_config(self): + todays_datetime = now_datetime().strftime('%Y%m%d_%H%M%S') + site_config_backup_path = os.path.join(get_backup_path(), "site_config_backup_{}.json".format(todays_datetime)) + site_config_path = os.path.join(frappe.get_site_path(), "site_config.json") + site_config = {} + if os.path.exists(site_config_path): + site_config.update(frappe.get_file_json(site_config_path)) + with open(site_config_backup_path, "w") as f: + f.write(json.dumps(site_config, indent=2)) + f.flush() + self.site_config_backup_path = site_config_backup_path + def take_dump(self): import frappe.utils