Skip to content

Commit

Permalink
feat: API to fetch the latest backup available
Browse files Browse the repository at this point in the history
Take a backup if it doesnt exist with the required expiry
  • Loading branch information
gavindsouza committed Jul 21, 2020
1 parent e3c707c commit 220b56f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frappe/utils/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ def get_backup():
recipient_list = odb.send_email()
frappe.msgprint(_("Download link for your backup will be emailed on the following email address: {0}").format(', '.join(recipient_list)))


@frappe.whitelist()
def fetch_latest_backups(with_files=True, recent=3):
"""Takes backup on-demand if doesnt exist satisfying the `recent` parameter
Only for: System Managers
Args:
with_files (bool, optional): If set, files will backuped up. Defaults to True.
recent (int, optional): Won't take a new backup if backup exists within this paramter. Defaults to 3 hours
Returns:
dict: relative Backup Paths
"""
frappe.only_for("System Manager")
odb = BackupGenerator(frappe.conf.db_name, frappe.conf.db_name, frappe.conf.db_password, db_host=frappe.db.host, db_type=frappe.conf.db_type, db_port=frappe.conf.db_port)
odb.get_backup(older_than=recent, ignore_files=not with_files)

return {
"database": odb.backup_path_files,
"public": odb.backup_path_db,
"private": odb.backup_path_private_files,
"config": odb.site_config_backup_path
}


def scheduled_backup(older_than=6, ignore_files=False, backup_path_db=None, backup_path_files=None, backup_path_private_files=None, force=False, verbose=False):
"""this function is called from scheduler
deletes backups older than 7 days
Expand Down

0 comments on commit 220b56f

Please sign in to comment.