2020-04-28 20:15:59 +00:00
|
|
|
import os
|
|
|
|
import frappe
|
2020-02-10 08:00:54 +00:00
|
|
|
from frappe.utils.backups import scheduled_backup
|
2020-04-28 20:15:59 +00:00
|
|
|
from frappe.utils import cint, get_sites, now
|
|
|
|
|
2020-02-10 08:00:54 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
def main():
|
|
|
|
installed_sites = ":".join(get_sites())
|
|
|
|
sites = os.environ.get("SITES", installed_sites).split(":")
|
2020-04-28 20:15:59 +00:00
|
|
|
with_files = cint(os.environ.get("WITH_FILES"))
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
backup(sites, with_files)
|
2020-06-29 17:58:10 +00:00
|
|
|
|
|
|
|
if frappe.redis_server:
|
|
|
|
frappe.redis_server.connection_pool.disconnect()
|
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
exit(0)
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|