forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filestore
36 lines (32 loc) · 1.29 KB
/
filestore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
CICD_PROJECT_ID = '[PROJECT_ID]'
SOURCE_INSTANCE_ZONE = '[FILESTORE_ZONE]'
SOURCE_INSTANCE_NAME = '[FILESTORE_NAME]'
SOURCE_FILE_SHARE_NAME = '[FILE_SHARE_NAME]'
BACKUP_REGION = '[BACKUP_REGION]'
import google.auth
import google.auth.transport.requests
from google.auth.transport.requests import AuthorizedSession
import time
import requests
import json
credentials, project = google.auth.default()
request = google.auth.transport.requests.Request()
credentials.refresh(request)
authed_session = AuthorizedSession(credentials)
def get_backup_ID():
return "mybackup-" + time.strftime("%Y%m%d-%H%M%S")
def create_backup(request):
trigger_run_url = "https://file.googleapis.com/v1p1alpha1/projects/{}/locations/{}/backups?backupId={}".format(CICD_PROJECT_ID, BACKUP_REGION, get_backup_ID())
headers = {
'Content-Type': 'application/json'
}
repo_source = {
"description": "my new backup",
"source_instance": "projects/{}/locations/{}/instances/{}".format(CICD_PROJECT_ID, SOURCE_INSTANCE_ZONE, SOURCE_INSTANCE_NAME),
"source_file_share": "{}".format(SOURCE_FILE_SHARE_NAME)
}
print(trigger_run_url)
r = authed_session.post(url=trigger_run_url, headers=headers, data=json.dumps(repo_source))
print(r.status_code)
print(r.json())
return str(r.json())