Last active
October 8, 2020 12:16
-
-
Save scmmishra/66243c6c38aefd2ee2b852309e4d7717 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
# Copyright (c) 2019, Frappe Technologies and contributors | |
# For license information, please see license.txt | |
from __future__ import unicode_literals | |
import frappe | |
import glob | |
import os | |
from frappe.utils import split_emails, get_backups_path, get_files_path | |
from frappe.utils.backups import BackupGenerator, new_backup | |
class RemoteBackupController: | |
def __init__(ignore_files, upload_folder, send_email, retry_count, max_backups): | |
self.ignore_files = ignore_files or True | |
self.upload_folder = upload_folder or "Frappe Backups" | |
self.send_email = send_email or False | |
self.retry_count = retry_count or 0 | |
self.completed = [] | |
self.failed = [] | |
self.files = [] | |
def prepare_backup(self): | |
backup = new_backup(ignore_files=self.ignore_files) | |
self.files.append(frappe._dict( | |
path = backup.backup_path_db, | |
type = 'Database', | |
file_name = os.path.basename(backup.backup_path_db), | |
)) | |
self.files.append(frappe._dict( | |
path = backup.backup_path_conf, | |
type = 'Site Config', | |
file_name = os.path.basename(backup.backup_path_conf), | |
)) | |
if not self.ignore_files: | |
self.files.append(frappe._dict( | |
path = backup.backup_path_files, | |
type = 'Public Files', | |
file_name = os.path.basename(backup.backup_path_files), | |
)) | |
self.files.append(frappe._dict( | |
path = backup.backup_path_private_files, | |
type = 'Private Files', | |
file_name = os.path.basename(backup.backup_path_private_files), | |
)) | |
def take_backup(self): | |
for backup_file in self.files: | |
status = self.upload(backup_file) | |
if status: | |
self.completed.append(backup_file) | |
else: | |
self.failed.append(backup_file) | |
def finish(self): | |
self.remove_old_backups() | |
self.send_email() | |
def send_email(self): | |
pass | |
def remove_old_backups(self): | |
# Override this to remove old backups | |
pass | |
def upload(self, backup_file): | |
# Override this to upload to the desired service | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment