From e1c3ae4e5feb72043c4b63a95ad2e2e5ec0646ba Mon Sep 17 00:00:00 2001 From: Lev Date: Tue, 9 Nov 2021 14:49:26 +0300 Subject: [PATCH] fix(frappe-worker): Default sites in backup command --- build/frappe-worker/commands/backup.py | 39 ++++++++++++++++++++++++ build/frappe-worker/docker-entrypoint.sh | 9 ++---- 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 build/frappe-worker/commands/backup.py diff --git a/build/frappe-worker/commands/backup.py b/build/frappe-worker/commands/backup.py new file mode 100644 index 00000000..b6aa60a2 --- /dev/null +++ b/build/frappe-worker/commands/backup.py @@ -0,0 +1,39 @@ +import os +import frappe +from frappe.utils.backups import scheduled_backup +from frappe.utils import cint, get_sites, now + + +def backup(sites, with_files=False): + for site in sites: + frappe.init(site) + frappe.connect() + odb = scheduled_backup( + ignore_files=not with_files, + backup_path_db=None, + backup_path_files=None, + backup_path_private_files=None, + force=True + ) + print("database backup taken -", odb.backup_path_db, "- on", now()) + if with_files: + print("files backup taken -", odb.backup_path_files, "- on", now()) + print("private files backup taken -", odb.backup_path_private_files, "- on", now()) + frappe.destroy() + + +def main(): + installed_sites = ":".join(get_sites()) + sites = os.environ.get("SITES", installed_sites).split(":") + with_files = cint(os.environ.get("WITH_FILES")) + + backup(sites, with_files) + + if frappe.redis_server: + frappe.redis_server.connection_pool.disconnect() + + exit(0) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/build/frappe-worker/docker-entrypoint.sh b/build/frappe-worker/docker-entrypoint.sh index 5065d2a9..6695ea7b 100755 --- a/build/frappe-worker/docker-entrypoint.sh +++ b/build/frappe-worker/docker-entrypoint.sh @@ -159,13 +159,8 @@ doctor) ;; backup) - if [[ -n $WITH_FILES ]]; then - WITH_FILES=--with-files - fi - - for site in ${SITES//:/ }; do - bench --site "$site" backup $WITH_FILES - done + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/backup.py + exit ;; console)