Пример #1
0
def take_backup_to_dropbox(retry_count=0, upload_db_backup=True):
    did_not_upload, error_log = [], []
    try:
        if cint(frappe.db.get_value("Dropbox Settings", None, "enabled")):
            validate_file_size()
            did_not_upload, error_log = backup_to_dropbox(upload_db_backup)
            if did_not_upload: raise Exception

            send_email(True, "Dropbox", "Dropbox Settings",
                       "send_notifications_to")
    except JobTimeoutException:
        if retry_count < 2:
            args = {
                "retry_count": retry_count + 1,
                "upload_db_backup":
                False  #considering till worker timeout db backup is uploaded
            }
            enqueue(
                "frappe.integrations.doctype.dropbox_settings.dropbox_settings.take_backup_to_dropbox",
                queue='long',
                timeout=1500,
                **args)
    except Exception:
        if isinstance(error_log, str):
            error_message = error_log + "\n" + frappe.get_traceback()
        else:
            file_and_error = [
                " - ".join(f) for f in zip(did_not_upload, error_log)
            ]
            error_message = ("\n".join(file_and_error) + "\n" +
                             frappe.get_traceback())
        send_email(False, "Dropbox", "Dropbox Settings",
                   "send_notifications_to", error_message)
Пример #2
0
 def start_taking_backup(self, retry_count=0, upload_db_backup=True):
     try:
         if self.enabled:
             validate_file_size()
             self.backup_to_nextcloud(upload_db_backup)
             if self.error_log:
                 raise Exception
             if self.send_email_for_successful_backup:
                 send_email(True, "Nextcloud", "Nextcloud Setting",
                            "send_notifications_to")
     except JobTimeoutException:
         if retry_count < 2:
             args = {
                 "retry_count": retry_count + 1,
                 "upload_db_backup":
                 False  #considering till worker timeout db backup is uploaded
             }
             enqueue(self.start_taking_backup,
                     queue='long',
                     timeout=1500,
                     **args)
     except Exception:
         if isinstance(self.error_log, str):
             error_message = self.error_log + "\n" + frappe.get_traceback()
         else:
             file_and_error = [
                 " - ".join(f) for f in zip(
                     self.failed_uploads if self.failed_uploads else '',
                     list(set(self.error_log)))
             ]
             error_message = ("\n".join(file_and_error) + "\n" +
                              frappe.get_traceback())
         send_email(False, "Nextcloud", "Nextcloud Setting",
                    "send_notifications_to", error_message)
Пример #3
0
def upload_system_backup_to_google_drive():
    """
		Upload system backup to Google Drive
	"""
    # Get Google Drive Object
    google_drive, account = get_google_drive_object()

    # Check if folder exists in Google Drive
    check_for_folder_in_google_drive()
    account.load_from_db()

    validate_file_size()
    if frappe.flags.create_new_backup:
        set_progress(1, "Backing up Data.")
        backup = new_backup()
        file_urls = []
        file_urls.append(backup.backup_path_db)
        file_urls.append(backup.site_config_backup_path)

        if account.file_backup:
            file_urls.append(backup.backup_path_files)
            file_urls.append(backup.backup_path_private_files)
    else:
        if account.file_backup:
            backup_files()
        file_urls = get_latest_backup_file(with_files=account.file_backup)

    for fileurl in file_urls:
        if not fileurl:
            continue

        file_metadata = {
            "name": fileurl,
            "parents": [account.backup_folder_id]
        }

        try:
            media = MediaFileUpload(get_absolute_path(filename=fileurl),
                                    mimetype="application/gzip",
                                    resumable=True)
        except IOError as e:
            frappe.throw(_("Google Drive - Could not locate - {0}").format(e))

        try:
            set_progress(2, "Uploading backup to Google Drive.")
            google_drive.files().create(body=file_metadata,
                                        media_body=media,
                                        fields="id").execute()
        except HttpError as e:
            send_email(False,
                       "Google Drive",
                       "Google Drive",
                       "email",
                       error_status=e)

    set_progress(3, "Uploading successful.")
    frappe.db.set_value("Google Drive", None, "last_backup_on",
                        frappe.utils.now_datetime())
    send_email(True, "Google Drive", "Google Drive", "email")
    return _("Google Drive Backup Successful.")
Пример #4
0
def take_backups_s3(retry_count=0):
	try:
		validate_file_size()
		backup_to_s3()
		send_email(True, "Amazon S3", "S3 Backup Settings", "notify_email")
	except JobTimeoutException:
		if retry_count < 2:
			args = {
				"retry_count": retry_count + 1
			}
			enqueue("frappe.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_s3",
				queue='long', timeout=1500, **args)
		else:
			notify()
	except Exception:
		notify()
Пример #5
0
def notify():
    error_message = frappe.get_traceback()
    send_email(False, 'Amazon S3', "S3 Backup Settings", "notify_email",
               error_message)