Skip to content

Commit

Permalink
Support for NBACKUP Service #PYFB-13
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Makowski committed Mar 14, 2012
1 parent 54ad904 commit 2a2aeda
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fdb/fbcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def bytes_to_int(b): # Read as little endian.
return struct.unpack(fmt, b)[0]


def bint_to_bytes(val, nbytes): # Convert int value to big endian bytes.
def bint_to_bytes(val, nbytes): # Convert int value to big endian bytes.
if nbytes == 1:
fmt = 'b'
elif nbytes == 2:
Expand Down
17 changes: 17 additions & 0 deletions fdb/ibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,17 @@ def mychr(i):
isc_action_svc_db_stats = 11 # Retrieves database statistics
isc_action_svc_get_ib_log = 12 # Retrieves the InterBase log file from the server
isc_action_svc_get_fb_log = 12 # Retrieves the Firebird log file from the server
isc_action_svc_nbak = 20
isc_action_svc_nrest = 21
isc_action_svc_trace_start = 22
isc_action_svc_trace_stop = 23
isc_action_svc_trace_suspend = 24
isc_action_svc_trace_resume = 25
isc_action_svc_trace_list = 26
isc_action_svc_set_mapping = 27
isc_action_svc_drop_mapping = 28
isc_action_svc_display_user_adm = 29
isc_action_svc_last = 30

# Service information items
isc_info_svc_svr_db_info = 50 # Retrieves the number of attachments and databases */
Expand Down Expand Up @@ -599,6 +610,7 @@ def mychr(i):
isc_spb_bkp_non_transportable = 0x20
isc_spb_bkp_convert = 0x40
isc_spb_bkp_expand = 0x80
isc_spb_bkp_no_triggers = 0x8000

# Parameters for isc_action_svc_properties
isc_spb_prp_page_buffers = 5
Expand Down Expand Up @@ -666,6 +678,11 @@ def mychr(i):
isc_spb_res_replace = 0x1000
isc_spb_res_create = 0x2000
isc_spb_res_use_all_space = 0x4000
isc_spb_res_metadata_only = 0x04

# Parameters for isc_action_svc_nbak
isc_spb_nbk_level = 5
isc_spb_nbk_file = 6

# Parameters for isc_spb_res_access_mode
isc_spb_res_am_readonly = isc_spb_prp_am_readonly
Expand Down
76 changes: 74 additions & 2 deletions fdb/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ def backup(self,
garbageCollect=1,
transportable=1,
convertExternalTablesToInternalTables=1,
expand=1 # YYY:What is this?
expand=1, # YYY:What is this?
nodbtriggers=0
):
# Begin parameter validation section.
_checkString(sourceDatabase)
Expand Down Expand Up @@ -641,6 +642,8 @@ def backup(self,
optionMask |= ibase.isc_spb_bkp_convert
if expand:
optionMask |= ibase.isc_spb_bkp_expand
if nodbtriggers:
optionMask |= ibase.isc_spb_bkp_no_triggers
# End option bitmask setup section.

# Construct the request buffer.
Expand Down Expand Up @@ -678,7 +681,9 @@ def restore(self,
doNotRestoreShadows=0,
doNotEnforceConstraints=0,
commitAfterEachTable=0,
useAllPageSpace=0
useAllPageSpace=0,
nodbtriggers=0,
metadataOnly=0
):
# Begin parameter validation section.
sourceFilenames = self._requireStrOrTupleOfStr(
Expand Down Expand Up @@ -710,6 +715,10 @@ def restore(self,
optionMask |= ibase.isc_spb_res_one_at_a_time
if useAllPageSpace:
optionMask |= ibase.isc_spb_res_use_all_space
if nodbtriggers:
optionMask |= ibase.isc_spb_bkp_no_triggers
if metadataOnly:
optionMask |= ibase.isc_spb_bkp_metadata_only
# End option bitmask setup section.

# Construct the request buffer.
Expand Down Expand Up @@ -754,6 +763,69 @@ def restore(self,

# Return the results to the caller synchronously.
return self._collectUnformattedResults()

# nbackup methods:

def nbackup(self, sourceDatabase, destFilename, nbackup_level=0,
nodbtriggers=0):
# Begin parameter validation section.
_checkString(sourceDatabase)
sourceDatabase = self._str_to_bytes(sourceDatabase)
_checkString(destFilename)
destFilename = self._str_to_bytes(destFilename)

# Begin option bitmask setup section.
optionMask = 0
if nodbtriggers:
optionMask |= ibase.isc_spb_bkp_no_triggers
# End option bitmask setup section.

# Construct the request buffer.
request = _ServiceActionRequestBuilder(ibase.isc_action_svc_nbak)

# Source database filename:
request.addDatabaseName(sourceDatabase)

# Backup filename:
request.addString(ibase.isc_spb_nbk_file, destFilename)

# backup level
request.addNumeric(ibase.isc_spb_nbk_level, nbackup_level)

# Options bitmask:
request.addNumeric(ibase.isc_spb_options, optionMask)

# Done constructing the request buffer.
return self._act(request)

def nrestore(self, sourceFilenames, destFilename, nodbtriggers=0):
# Begin parameter validation section.
sourceFilenames = self._requireStrOrTupleOfStr(
self._str_to_bytes(sourceFilenames)
)
destFilename = self._str_to_bytes(destFilename)

# Begin option bitmask setup section.
optionMask = 0
if nodbtriggers:
optionMask |= ibase.isc_spb_bkp_no_triggers
# End option bitmask setup section.

# Construct the request buffer.
request = _ServiceActionRequestBuilder(ibase.isc_action_svc_nrest)

# Backup filenames:
request.addSequenceOfStrings(ibase.isc_spb_nbk_file, sourceFilenames)

# Source database filename:
request.addString(ibase.isc_spb_dbname, destFilename)

# Options bitmask:
request.addNumeric(ibase.isc_spb_options, optionMask)

# Done constructing the request buffer.
return self._act(request)

# Database property alteration methods:

def setDefaultPageBuffers(self, database, n):
Expand Down

0 comments on commit 2a2aeda

Please sign in to comment.