testgres-pg-probackup2 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pg_probackup2/__init__.py +0 -0
- pg_probackup2/app.py +762 -0
- pg_probackup2/gdb.py +346 -0
- pg_probackup2/init_helpers.py +207 -0
- pg_probackup2/storage/__init__.py +0 -0
- pg_probackup2/storage/fs_backup.py +101 -0
- pg_probackup2/storage/s3_backup.py +134 -0
- testgres_pg_probackup2-0.0.1.dist-info/METADATA +15 -0
- testgres_pg_probackup2-0.0.1.dist-info/RECORD +11 -0
- testgres_pg_probackup2-0.0.1.dist-info/WHEEL +5 -0
- testgres_pg_probackup2-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import io
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import minio
|
|
6
|
+
from minio import Minio
|
|
7
|
+
from minio.deleteobjects import DeleteObject
|
|
8
|
+
import urllib3
|
|
9
|
+
from .fs_backup import TestBackupDir
|
|
10
|
+
|
|
11
|
+
root = os.path.realpath(os.path.join(os.path.dirname(__file__), '../..'))
|
|
12
|
+
if root not in sys.path:
|
|
13
|
+
sys.path.append(root)
|
|
14
|
+
|
|
15
|
+
# Should fail if either of env vars does not exist
|
|
16
|
+
host = os.environ['PG_PROBACKUP_S3_HOST']
|
|
17
|
+
port = os.environ['PG_PROBACKUP_S3_PORT']
|
|
18
|
+
access = os.environ['PG_PROBACKUP_S3_ACCESS_KEY']
|
|
19
|
+
secret = os.environ['PG_PROBACKUP_S3_SECRET_ACCESS_KEY']
|
|
20
|
+
bucket = os.environ['PG_PROBACKUP_S3_BUCKET_NAME']
|
|
21
|
+
path_suffix = os.environ.get("PG_PROBACKUP_TEST_TMP_SUFFIX")
|
|
22
|
+
https = os.environ.get("PG_PROBACKUP_S3_HTTPS")
|
|
23
|
+
|
|
24
|
+
s3_type = os.environ.get('PG_PROBACKUP_S3_TEST', os.environ.get('PROBACKUP_S3_TYPE_FULL_TEST'))
|
|
25
|
+
tmp_path = os.environ.get('PGPROBACKUP_TMP_DIR', default='')
|
|
26
|
+
|
|
27
|
+
status_forcelist = [413, # RequestBodyTooLarge
|
|
28
|
+
429, # TooManyRequests
|
|
29
|
+
500, # InternalError
|
|
30
|
+
503, # ServerBusy
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class S3TestBackupDir(TestBackupDir):
|
|
35
|
+
is_file_based = False
|
|
36
|
+
|
|
37
|
+
def __init__(self, *, rel_path, backup):
|
|
38
|
+
path = "pg_probackup"
|
|
39
|
+
if path_suffix:
|
|
40
|
+
path += "_" + path_suffix
|
|
41
|
+
if tmp_path == '' or os.path.isabs(tmp_path):
|
|
42
|
+
self.path = f"{path}{tmp_path}/{rel_path}/{backup}"
|
|
43
|
+
else:
|
|
44
|
+
self.path = f"{path}/{tmp_path}/{rel_path}/{backup}"
|
|
45
|
+
|
|
46
|
+
secure: bool = False
|
|
47
|
+
if https in ['ON', 'HTTPS']:
|
|
48
|
+
secure = True
|
|
49
|
+
self.conn = Minio(host + ":" + port, secure=secure, access_key=access,
|
|
50
|
+
secret_key=secret, http_client=urllib3.PoolManager(retries=urllib3.Retry(total=5,
|
|
51
|
+
backoff_factor=1,
|
|
52
|
+
status_forcelist=status_forcelist)))
|
|
53
|
+
if not self.conn.bucket_exists(bucket):
|
|
54
|
+
raise Exception(f"Test bucket {bucket} does not exist.")
|
|
55
|
+
self.pb_args = ('-B', '/' + self.path, f'--s3={s3_type}')
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
def list_instance_backups(self, instance):
|
|
59
|
+
full_path = os.path.join(self.path, 'backups', instance)
|
|
60
|
+
candidates = self.conn.list_objects(bucket, prefix=full_path, recursive=True)
|
|
61
|
+
return [os.path.basename(os.path.dirname(x.object_name))
|
|
62
|
+
for x in candidates if x.object_name.endswith('backup.control')]
|
|
63
|
+
|
|
64
|
+
def list_files(self, sub_dir, recursive=False):
|
|
65
|
+
full_path = os.path.join(self.path, sub_dir)
|
|
66
|
+
# Need '/' in the end to find inside the folder
|
|
67
|
+
full_path_dir = full_path if full_path[-1] == '/' else full_path + '/'
|
|
68
|
+
object_list = self.conn.list_objects(bucket, prefix=full_path_dir, recursive=recursive)
|
|
69
|
+
return [obj.object_name.replace(full_path_dir, '', 1)
|
|
70
|
+
for obj in object_list
|
|
71
|
+
if not obj.is_dir]
|
|
72
|
+
|
|
73
|
+
def list_dirs(self, sub_dir):
|
|
74
|
+
full_path = os.path.join(self.path, sub_dir)
|
|
75
|
+
# Need '/' in the end to find inside the folder
|
|
76
|
+
full_path_dir = full_path if full_path[-1] == '/' else full_path + '/'
|
|
77
|
+
object_list = self.conn.list_objects(bucket, prefix=full_path_dir, recursive=False)
|
|
78
|
+
return [obj.object_name.replace(full_path_dir, '', 1).rstrip('\\/')
|
|
79
|
+
for obj in object_list
|
|
80
|
+
if obj.is_dir]
|
|
81
|
+
|
|
82
|
+
def read_file(self, sub_path, *, text=True):
|
|
83
|
+
full_path = os.path.join(self.path, sub_path)
|
|
84
|
+
bytes = self.conn.get_object(bucket, full_path).read()
|
|
85
|
+
if not text:
|
|
86
|
+
return bytes
|
|
87
|
+
return bytes.decode('utf-8')
|
|
88
|
+
|
|
89
|
+
def write_file(self, sub_path, data, *, text=True):
|
|
90
|
+
full_path = os.path.join(self.path, sub_path)
|
|
91
|
+
if text:
|
|
92
|
+
data = data.encode('utf-8')
|
|
93
|
+
self.conn.put_object(bucket, full_path, io.BytesIO(data), length=len(data))
|
|
94
|
+
|
|
95
|
+
def cleanup(self):
|
|
96
|
+
self.remove_dir('')
|
|
97
|
+
|
|
98
|
+
def remove_file(self, sub_path):
|
|
99
|
+
full_path = os.path.join(self.path, sub_path)
|
|
100
|
+
self.conn.remove_object(bucket, full_path)
|
|
101
|
+
|
|
102
|
+
def remove_dir(self, sub_path):
|
|
103
|
+
if sub_path:
|
|
104
|
+
full_path = os.path.join(self.path, sub_path)
|
|
105
|
+
else:
|
|
106
|
+
full_path = self.path
|
|
107
|
+
objs = self.conn.list_objects(bucket, prefix=full_path, recursive=True,
|
|
108
|
+
include_version=True)
|
|
109
|
+
delobjs = (DeleteObject(o.object_name, o.version_id) for o in objs)
|
|
110
|
+
errs = list(self.conn.remove_objects(bucket, delobjs))
|
|
111
|
+
if errs:
|
|
112
|
+
strerrs = "; ".join(str(err) for err in errs)
|
|
113
|
+
raise Exception("There were errors: {0}".format(strerrs))
|
|
114
|
+
|
|
115
|
+
def exists(self, sub_path):
|
|
116
|
+
full_path = os.path.join(self.path, sub_path)
|
|
117
|
+
try:
|
|
118
|
+
self.conn.stat_object(bucket, full_path)
|
|
119
|
+
return True
|
|
120
|
+
except minio.error.S3Error as s3err:
|
|
121
|
+
if s3err.code == 'NoSuchKey':
|
|
122
|
+
return False
|
|
123
|
+
raise s3err
|
|
124
|
+
except Exception as err:
|
|
125
|
+
raise err
|
|
126
|
+
|
|
127
|
+
def __str__(self):
|
|
128
|
+
return '/' + self.path
|
|
129
|
+
|
|
130
|
+
def __repr__(self):
|
|
131
|
+
return "S3TestBackupDir" + str(self.path)
|
|
132
|
+
|
|
133
|
+
def __fspath__(self):
|
|
134
|
+
return self.path
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: testgres-pg-probackup2
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Plugin for testgres that manages pg_probackup2
|
|
5
|
+
Home-page: https://github.com/postgrespro/testgres
|
|
6
|
+
Author: Postgres Professional
|
|
7
|
+
Author-email: testgres@postgrespro.ru
|
|
8
|
+
License: PostgreSQL
|
|
9
|
+
Keywords: pg_probackup,testing,testgres
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: testgres (>=1.9.2)
|
|
13
|
+
|
|
14
|
+
UNKNOWN
|
|
15
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
pg_probackup2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pg_probackup2/app.py,sha256=nXwVSk6o7MaLSAHhnO4pTpTTEywgZC0lFSjtZ14SckY,27390
|
|
3
|
+
pg_probackup2/gdb.py,sha256=wHZF9apMQwkZcGznCqPfbVEaS8iVvOB32KfsehPy1R0,10031
|
|
4
|
+
pg_probackup2/init_helpers.py,sha256=sR0Ib16TNXvP_7gH8BTFGOsWMTCxf9NCXWXpmcbjYmY,7406
|
|
5
|
+
pg_probackup2/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
pg_probackup2/storage/fs_backup.py,sha256=1-Fs15XjVgKFwN--f2C9VgU7xZ8iRl8bG27dK5dRJlE,3121
|
|
7
|
+
pg_probackup2/storage/s3_backup.py,sha256=_TNd4m9-3QkzV9zCPj5WQq1BWYblT84nS9HHl5s22T0,5301
|
|
8
|
+
testgres_pg_probackup2-0.0.1.dist-info/METADATA,sha256=ly7OCctQJ1eMdGgOJ3PE2Coq6UNooC5JYV_vlJaaIfA,403
|
|
9
|
+
testgres_pg_probackup2-0.0.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
10
|
+
testgres_pg_probackup2-0.0.1.dist-info/top_level.txt,sha256=u_wH4GLHXhlgIwNar9-iv65Y3WDDg1b8v8bm5jUHulk,14
|
|
11
|
+
testgres_pg_probackup2-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pg_probackup2
|