示例#1
0
def backup_to_dropbox():
	from dropbox import client, session
	from conf import dropbox_access_key, dropbox_secret_key
	from webnotes.utils.backups import new_backup
	if not webnotes.conn:
		webnotes.connect()

	sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")

	sess.set_token(webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
		webnotes.conn.get_value("Backup Manager", None, "dropbox_access_secret"))
	
	dropbox_client = client.DropboxClient(sess)

	# upload database
	backup = new_backup()
	filename = os.path.join(get_base_path(), "public", "backups", 
		os.path.basename(backup.backup_path_db))
	upload_file_to_dropbox(filename, "database", dropbox_client)

	response = dropbox_client.metadata("/files")
	# upload files to files folder
	path = os.path.join(get_base_path(), "public", "files")
	for filename in os.listdir(path):
		found = False
		filepath = os.path.join(path, filename)
		for file_metadata in response["contents"]:
 			if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
				found = True
				break
		if not found:
			upload_file_to_dropbox(filepath, "files", dropbox_client)
示例#2
0
def backup_to_dropbox():
	from dropbox import client, session
	from conf import dropbox_access_key, dropbox_secret_key
	from webnotes.utils.backups import new_backup
	if not webnotes.conn:
		webnotes.connect()


	sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")

	sess.set_token(webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
		webnotes.conn.get_value("Backup Manager", None, "dropbox_access_secret"))
	
	dropbox_client = client.DropboxClient(sess)

	# upload database
	backup = new_backup()
	filename = backup.backup_path_db
	upload_file_to_dropbox(filename, "database", dropbox_client)

	# upload files
	response = dropbox_client.metadata("files")

	
	# add missing files
	for filename in os.listdir(os.path.join("public", "files")):
		found = False
		for file_metadata in response["contents"]:
 			if filename==os.path.basename(file_metadata["path"]):
				if os.stat(os.path.join("public", "files", filename)).st_size==file_metadata["bytes"]:
					found=True

		if not found:
			upload_file_to_dropbox(os.path.join("public", "files", filename), "files", dropbox_client)
示例#3
0
def backup_to_gdrive():
    from webnotes.utils.backups import new_backup
    if not webnotes.conn:
        webnotes.connect()
    get_gdrive_flow()
    credentials_json = webnotes.conn.get_value("Backup Manager", None,
                                               "gdrive_credentials")
    credentials = oauth2client.client.Credentials.new_from_json(
        credentials_json)
    http = httplib2.Http()
    http = credentials.authorize(http)
    drive_service = build('drive', 'v2', http=http)

    # upload database
    backup = new_backup()
    path = os.path.join(get_base_path(), "public", "backups")
    filename = os.path.join(path, os.path.basename(backup.backup_path_db))

    # upload files to database folder
    upload_files(
        filename, 'application/x-gzip', drive_service,
        webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))

    # upload files to files folder
    did_not_upload = []
    error_log = []

    files_folder_id = webnotes.conn.get_value("Backup Manager", None,
                                              "files_folder_id")

    webnotes.conn.close()
    path = os.path.join(get_base_path(), "public", "files")
    for filename in os.listdir(path):
        filename = cstr(filename)
        found = False
        filepath = os.path.join(path, filename)
        ext = filename.split('.')[-1]
        size = os.path.getsize(filepath)
        if ext == 'gz' or ext == 'gzip':
            mimetype = 'application/x-gzip'
        else:
            mimetype = mimetypes.types_map.get(
                "." + ext) or "application/octet-stream"

        #Compare Local File with Server File
        children = drive_service.children().list(
            folderId=files_folder_id).execute()
        for child in children.get('items', []):
            file = drive_service.files().get(fileId=child['id']).execute()
            if filename == file['title'] and size == int(file['fileSize']):
                found = True
                break
        if not found:
            try:
                upload_files(filepath, mimetype, drive_service,
                             files_folder_id)
            except Exception, e:
                did_not_upload.append(filename)
                error_log.append(cstr(e))
示例#4
0
def backup_to_dropbox():
    from dropbox import client, session
    from conf import dropbox_access_key, dropbox_secret_key
    from webnotes.utils.backups import new_backup
    from webnotes.utils import get_files_path, get_backups_path
    if not webnotes.conn:
        webnotes.connect()

    sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key,
                                  "app_folder")

    sess.set_token(
        webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
        webnotes.conn.get_value("Backup Manager", None,
                                "dropbox_access_secret"))

    dropbox_client = client.DropboxClient(sess)

    # upload database
    backup = new_backup()
    filename = os.path.join(get_backups_path(),
                            os.path.basename(backup.backup_path_db))
    upload_file_to_dropbox(filename, "/database", dropbox_client)

    webnotes.conn.close()
    response = dropbox_client.metadata("/files")

    # upload files to files folder
    did_not_upload = []
    error_log = []
    path = get_files_path()
    for filename in os.listdir(path):
        filename = cstr(filename)
        if filename in ignore_list:
            continue

        found = False
        filepath = os.path.join(path, filename)
        for file_metadata in response["contents"]:
            if os.path.basename(filepath) == os.path.basename(
                    file_metadata["path"]) and os.stat(
                        filepath).st_size == int(file_metadata["bytes"]):
                found = True
                break
        if not found:
            try:
                upload_file_to_dropbox(filepath, "/files", dropbox_client)
            except Exception:
                did_not_upload.append(filename)
                error_log.append(webnotes.getTraceback())

    webnotes.connect()
    return did_not_upload, list(set(error_log))
示例#5
0
def backup_to_gdrive():
	from webnotes.utils.backups import new_backup
	if not webnotes.conn:
		webnotes.connect()
	get_gdrive_flow()
	credentials_json = webnotes.conn.get_value("Backup Manager", None, "gdrive_credentials")
	credentials = oauth2client.client.Credentials.new_from_json(credentials_json)
	http = httplib2.Http()
	http = credentials.authorize(http)
	drive_service = build('drive', 'v2', http=http)

	# upload database
	backup = new_backup()
	path = os.path.join(get_base_path(), "public", "backups")
	filename = os.path.join(path, os.path.basename(backup.backup_path_db))
	
	# upload files to database folder
	upload_files(filename, 'application/x-gzip', drive_service, 
		webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))
	
	# upload files to files folder
	did_not_upload = []
	error_log = []
	
	files_folder_id = webnotes.conn.get_value("Backup Manager", None, "files_folder_id")
	
	webnotes.conn.close()
	path = os.path.join(get_base_path(), "public", "files")
	for filename in os.listdir(path):
		found = False
		filepath = os.path.join(path, filename)
		ext = filename.split('.')[-1]
		size = os.path.getsize(filepath)
		if ext == 'gz' or ext == 'gzip':
			mimetype = 'application/x-gzip'
		else:
			mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
		
		#Compare Local File with Server File
		param = {}
	  	children = drive_service.children().list(folderId=files_folder_id, **param).execute()
	  	for child in children.get('items', []):
			file = drive_service.files().get(fileId=child['id']).execute()
			if filename == file['title'] and size == int(file['fileSize']):
				found = True
				break
		if not found:
			try:
				upload_files(filepath, mimetype, drive_service, files_folder_id)
			except Exception, e:
				did_not_upload.append(filename)
				error_log.append(cstr(e))
示例#6
0
def backup_to_dropbox():
    from dropbox import client, session
    from conf import dropbox_access_key, dropbox_secret_key
    from webnotes.utils.backups import new_backup

    if not webnotes.conn:
        webnotes.connect()

    sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")

    sess.set_token(
        webnotes.conn.get_value("Backup Manager", None, "dropbox_access_key"),
        webnotes.conn.get_value("Backup Manager", None, "dropbox_access_secret"),
    )

    dropbox_client = client.DropboxClient(sess)

    # upload database
    backup = new_backup()
    filename = os.path.join(get_base_path(), "public", "backups", os.path.basename(backup.backup_path_db))
    upload_file_to_dropbox(filename, "/database", dropbox_client)

    webnotes.conn.close()
    response = dropbox_client.metadata("/files")

    # upload files to files folder
    did_not_upload = []
    error_log = []
    path = os.path.join(get_base_path(), "public", "files")
    for filename in os.listdir(path):
        filename = cstr(filename)
        if filename in ignore_list:
            continue

        found = False
        filepath = os.path.join(path, filename)
        for file_metadata in response["contents"]:
            if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(
                filepath
            ).st_size == int(file_metadata["bytes"]):
                found = True
                break
        if not found:
            try:
                upload_file_to_dropbox(filepath, "/files", dropbox_client)
            except Exception:
                did_not_upload.append(filename)
                error_log.append(webnotes.getTraceback())

    webnotes.connect()
    return did_not_upload, list(set(error_log))
示例#7
0
def backup_to_gdrive():
	from webnotes.utils.backups import new_backup
	found_database = False
	found_files = False
	if not webnotes.conn:
		webnotes.connect()
	flow = get_gdrive_flow()
	credentials_json = webnotes.conn.get_value("Backup Manager", None, "gdrive_credentials")
	credentials = oauth2client.client.Credentials.new_from_json(credentials_json)
	http = httplib2.Http()
	http = credentials.authorize(http)
	drive_service = build('drive', 'v2', http=http)

	# upload database
	backup = new_backup()
	path = os.path.join(get_base_path(), "public", "backups")
	filename = os.path.join(path, os.path.basename(backup.backup_path_db))
	
	# upload files to database folder
	upload_files(filename, 'application/x-gzip', drive_service, 
		webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))

	# upload files to files folder
	path = os.path.join(get_base_path(), "public", "files")
	for files in os.listdir(path):
		filename = path + "/" + files
		ext = filename.split('.')[-1]
		size = os.path.getsize(filename)
		if ext == 'gz' or ext == 'gzip':
			mimetype = 'application/x-gzip'
		else:
			mimetype = mimetypes.types_map["." + ext]
		#Compare Local File with Server File
		param = {}
	  	children = drive_service.children().list(
			folderId=webnotes.conn.get_value("Backup Manager", None, "files_folder_id"), 
			**param).execute()
	  	for child in children.get('items', []):
			file = drive_service.files().get(fileId=child['id']).execute()
			if files == file['title'] and size == int(file['fileSize']):
				found_files = True
				break
		if not found_files:
			upload_files(filename, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))