GroveStreams

Backup Orgaization Python Script517

MikeMills private msg quote post Address this user
Below is an example script to get a GroveStreams session token and use that token to download an organization backup file using the GroveStreams HTTP restful API.

It is written using Python 3.7.

# GroveStreams.com Python 3.7 Feed Example
# Demonstrates getting a session token and backing up an organization to a local file
 
 
# License:
# Copyright 2019 GroveStreams LLC.
# Licensed under the Apache License, Version 2.0 (the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import requests
import datetime;
 
if __name__ == '__main__':
 
    #CHANGE THESE!!!!!!
    userId = "brucelee@acme.com"
    userPwd = "wingchung"
    org = 'af5da88b-1487-3873-a7c4-5ea69d867f3a'     
    backupFile = "/home/gs/gs_backup_" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M') + ".zip"  #This is a linux directory. Change it to a Windows directory if that's what you're using
    
 
    try:    
        # Login and get a use session token
        url = "https://grovestreams.com/api/login"
        data = {
            "email": userId,
            "password" : userPwd
        }
 
        response = requests.post(
            url,
            json=data
        )
        if response.status_code != 200 and response.status_code != 201:
            try:
                if (response.reason != None):
                    print('HTTP Failure Reason: ' + response.reason + ' body: ' + response.read().decode(encoding='UTF-8'))
                else:
                    print('HTTP Failure Body: ' + response.read().decode(encoding='UTF-8'))
            except Exception:
                print('HTTP Failure Status: %d' % (response.status_code))
 
 
        json_response = response.json()
        session = json_response["sessionUid"]
 
        #Download the Backup File
        url = "https://grovestreams.com/api/organization/backup?org=" + org + "&time=&exportAll=true&compDir=&contentDir=&session=" + session
        chunk_size = 100000
 
        r = requests.get(url, stream=True)
        with open(backupFile, 'wb') as fd:
            for chunk in r.iter_content(chunk_size):
                fd.write(chunk)
 
        if response.status_code != 200 and response.status_code != 201:
            try:
                if (response.reason != None):
                    print('HTTP Failure Reason: ' + response.reason + ' body: ' + response.read().decode(encoding='UTF-8'))
                else:
                    print('HTTP Failure Body: ' + response.read().decode(encoding='UTF-8'))
            except Exception:
                print('HTTP Failure Status: %d' % (response.status_code))
 
    except Exception as e:
        print('HTTP Failure: ' + str(e))
 
 
    # quit
    exit(0)
 
Post 1 IP   flag post
Essential_WD private msg quote post Address this user
Hello!
What capabilities must the user's group have for downloading the backup? Must the user be a part of the administrator group for the backup download to be successful? I wish to give my backup account minimal permissions to download the zip file, and nothing more. Every combination I've tried thus far has resulted in an empty zip file being downloaded, and only when the backup account is in the administrators group does the backup work. Is there a workaround to this?
-WD
Post 2 IP   flag post
MikeMills private msg quote post Address this user
One of the User's Groups must have Manage Exports capability and the user/group must have Traverse rights for the content store folders and objects (Components, Content, Tools) they are backing up.

Right click on the store folders, choose properties, and check the security tab.

Aren't there errors in the Org's System Notifications when the zip file is empty?

We did some work in this area last week to improve backup times. We could've introduced an issue. That's why I'm asking about the notifications.
Post 3 IP   flag post
2895 3 3
Log in or sign up to compose a reply.