summaryrefslogtreecommitdiff
path: root/trove/common
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2021-02-16 12:23:19 +1300
committerLingxian Kong <anlin.kong@gmail.com>2021-02-18 17:34:37 +0000
commit6fdf11ea7f5c77e83dd746fa33b7a354417aec08 (patch)
treed66f3528a6a36911dd55ce654b095aca8cceb3aa /trove/common
parent9c2e0bf3a0f1bc0b35a148174d8a4d2083f2b3c5 (diff)
downloadtrove-6fdf11ea7f5c77e83dd746fa33b7a354417aec08.tar.gz
Support to restore backup from remote location
In multi-region deployment with geo-replicated Swift, the user can restore a backup in one region by manually specifying the original backup data location created in another region. Change-Id: Iefef3bf969163af707935445bc23299400dc88c3
Diffstat (limited to 'trove/common')
-rw-r--r--trove/common/apischema.py17
-rw-r--r--trove/common/constants.py16
-rw-r--r--trove/common/swift.py42
3 files changed, 73 insertions, 2 deletions
diff --git a/trove/common/apischema.py b/trove/common/apischema.py
index 4c799992..bc815fad 100644
--- a/trove/common/apischema.py
+++ b/trove/common/apischema.py
@@ -652,14 +652,27 @@ backup = {
"properties": {
"backup": {
"type": "object",
- "required": ["instance", "name"],
+ "required": ["name"],
"properties": {
"description": non_empty_string,
"instance": uuid,
"name": non_empty_string,
"parent_id": uuid,
"incremental": boolean_string,
- "swift_container": non_empty_string
+ "swift_container": non_empty_string,
+ "restore_from": {
+ "type": "object",
+ "required": [
+ "remote_location",
+ "local_datastore_version_id",
+ "size"
+ ],
+ "properties": {
+ "remote_location": non_empty_string,
+ "local_datastore_version_id": uuid,
+ "size": {"type": "number"}
+ }
+ }
}
}
}
diff --git a/trove/common/constants.py b/trove/common/constants.py
new file mode 100644
index 00000000..0f53477b
--- /dev/null
+++ b/trove/common/constants.py
@@ -0,0 +1,16 @@
+# Copyright 2021 Catalyst Cloud Ltd.
+#
+# 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.
+
+BACKUP_TYPE_FULL = 'full'
+BACKUP_TYPE_INC = 'incremental'
diff --git a/trove/common/swift.py b/trove/common/swift.py
new file mode 100644
index 00000000..43910af1
--- /dev/null
+++ b/trove/common/swift.py
@@ -0,0 +1,42 @@
+# Copyright 2021 Catalyst Cloud Ltd.
+#
+# 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.
+
+
+def parse_location(location):
+ storage_url = "/".join(location.split('/')[:-2])
+ container_name = location.split('/')[-2]
+ object_name = location.split('/')[-1]
+ return storage_url, container_name, object_name
+
+
+def _get_attr(original):
+ """Get a friendly name from an object header key."""
+ key = original.replace('-', '_')
+ key = key.replace('x_object_meta_', '')
+ return key
+
+
+def get_metadata(client, location, extra_attrs=[]):
+ _, container_name, object_name = parse_location(location)
+ headers = client.head_object(container_name, object_name)
+
+ meta = {}
+ for key, value in headers.items():
+ if key.startswith('x-object-meta'):
+ meta[_get_attr(key)] = value
+
+ for key in extra_attrs:
+ meta[key] = headers.get(key)
+
+ return meta