Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita731c20

Browse files
committed
enum for xlog_method in NodeBackup
1 parentcf03ee2 commita731c20

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

‎testgres/backup.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
importtempfile
66

77
fromsiximportraise_from
8+
fromenumimportEnum
89

910
from .constsimport \
1011
DATA_DIR, \
1112
PG_CONF_FILE, \
12-
BACKUP_LOG_FILE, \
13-
DEFAULT_XLOG_METHOD
13+
BACKUP_LOG_FILE
1414

1515
from .exceptionsimportBackupException
1616

@@ -20,6 +20,16 @@
2020
execute_utility
2121

2222

23+
classXLogMethod(Enum):
24+
"""
25+
Available WAL methods for NodeBackup
26+
"""
27+
28+
none='none'
29+
fetch='fetch'
30+
stream='stream'
31+
32+
2333
classNodeBackup(object):
2434
"""
2535
Smart object responsible for backups
@@ -33,7 +43,7 @@ def __init__(self,
3343
node,
3444
base_dir=None,
3545
username=None,
36-
xlog_method=DEFAULT_XLOG_METHOD):
46+
xlog_method=XLogMethod.fetch):
3747
"""
3848
Create a new backup.
3949
@@ -47,6 +57,13 @@ def __init__(self,
4757
ifnotnode.status():
4858
raiseBackupException('Node must be running')
4959

60+
# Check arguments
61+
ifnotisinstance(xlog_method,XLogMethod):
62+
try:
63+
xlog_method=XLogMethod(xlog_method)
64+
exceptValueError:
65+
raiseBackupException('Invalid xlog_method "{}"'.format(xlog_method))
66+
5067
# Set default arguments
5168
username=usernameordefault_username()
5269
base_dir=base_dirortempfile.mkdtemp()
@@ -68,7 +85,7 @@ def __init__(self,
6885
"-h",node.host,
6986
"-U",username,
7087
"-D",data_dir,
71-
"-X",xlog_method
88+
"-X",xlog_method.value
7289
]
7390
execute_utility(_params,self.log_file)
7491

‎testgres/consts.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@
1212
PG_LOG_FILE="postgresql.log"
1313
UTILS_LOG_FILE="utils.log"
1414
BACKUP_LOG_FILE="backup.log"
15-
16-
# default argument value
17-
DEFAULT_XLOG_METHOD="fetch"

‎testgres/node.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
HBA_CONF_FILE, \
2828
RECOVERY_CONF_FILE, \
2929
PG_LOG_FILE, \
30-
UTILS_LOG_FILE, \
31-
DEFAULT_XLOG_METHOD
30+
UTILS_LOG_FILE
3231

3332
from .exceptionsimport \
3433
CatchUpException, \
@@ -52,6 +51,10 @@
5251
method_decorator, \
5352
positional_args_hack
5453

54+
from .backupimport \
55+
XLogMethod, \
56+
NodeBackup
57+
5558

5659
classNodeStatus(IntEnum):
5760
"""
@@ -838,7 +841,7 @@ def execute(self,
838841

839842
returnres
840843

841-
defbackup(self,username=None,xlog_method=DEFAULT_XLOG_METHOD):
844+
defbackup(self,username=None,xlog_method=XLogMethod.fetch):
842845
"""
843846
Perform pg_basebackup.
844847
@@ -850,15 +853,14 @@ def backup(self, username=None, xlog_method=DEFAULT_XLOG_METHOD):
850853
A smart object of type NodeBackup.
851854
"""
852855

853-
from .backupimportNodeBackup
854856
returnNodeBackup(node=self,
855857
username=username,
856858
xlog_method=xlog_method)
857859

858860
defreplicate(self,
859861
name=None,
860862
username=None,
861-
xlog_method=DEFAULT_XLOG_METHOD,
863+
xlog_method=XLogMethod.fetch,
862864
use_logging=False):
863865
"""
864866
Create a binary replica of this node.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp