Documentation for PythonAPI
22.40.00py2

packetlogic2.pldb.backup

This module contains functionality for managing backups on the PacketLogic system.

Do NOT import this module directly. The PLConnection object should be used, e.g:

>>> import packetlogic2
>>> pl = packetlogic2.connect("192.168.1.25", "admin", "password")
>>> b = pl.Backup()

Classes defined here:

  • Backup - A connection to a PacketLogic's "Backup" resource

Backup

A connection to a PacketLogic's "Backup" resource.

The methods of this object allows listing, taking and restoring backups on the PacketLogic system.

Inherits from: Resource
Methods:
Backup list of dict list(self)
List backups stored on server
restore(self, name, section='All', systemid='local')
Restore a backup
str take(self, name='', resource='')
Take a new backup
Ungrouped str download(self, name)
Download specified backup file
download_to(self, name, destpath)
Download specified backup file to a local file
remove(self, name)
Remove a backup file
upload(self, fname, data)
Upload a backup
upload_from(self, fname, srcpath)
Upload a backup from a local file
Inherited from Resource close(self)
Immediately disconnects the resource
commit(self, message='PythonAPI commit')
Store the current transaction to the database
ping(self, string='')
Send a command to server to test if it is up
tuple of (str, int) protocol(self, protocol, strict=False)
Translate protocol name OR number to tuple with name AND number
dict of str:int and int:str protocols_dict(self)
Returns a dictionary with name:nr and nr:name items for IP protocols
rollback(self)
Abort the current transaction and discard the data
services_cmd(self, services=[], props=[])
Send services to pldbd
list of str services_list(self)
List all services
list of str services_prop_list(self)
List all properties
wait_for_commit(self, pinginterval=60)
Wait for new data to be committed on resource
list of str xfb_flags_list(self)
List all XFB (Transfer Behaviour) flags, that can be used in FlagObjects
Properties:
commitid The CommitID associated with this session

close(self)

Immediately disconnects the resource.

After this method has been called this object becomes useless.

It may be used to force a disconnect when the garbage collector can't be trusted to do a timely disconnect.

commit(self, message='PythonAPI commit')

Store the current transaction to the database.

When you do this PacketLogic will reload the ruleset. This will take a lot of CPU resources from the system, try to do this in batches.

Observe that if you don't commit the changes you've made, no other resource (including the client) will see your changes.

Parameters:
  • message (str) - Message recorded in the commit log. Ignored in v12.1 and earlier.
  • message parameter is ignored in v12.1 firmware and earlier.

download(self, name)

Download specified backup file.

>>> plb = b.download("20090916-16.24.plb")
>>> len(plb)
596406L
>>> plb[:52]
"<?xml version='1.0' encoding='UTF-8'?>\n<PacketLogic "
Returns:
  • The contents of the requested backup.
  • str
Parameters:
  • name (str) - Name of backup to download.

download_to(self, name, destpath)

Download specified backup file to a local file

>>> download_to("20090916-16.24.plb", "/tmp/back.plb")
Parameters:
  • name (str) - Name of backup to download.
  • destpath (str) - Destination path for downloaded file

list(self)

List backups stored on server.

>>> b.list()
[{'cdate': '', 'path': '20090520-05.14.plb', 'size': 353714L},
 {'cdate': '', 'path': '20090731-22.52.plb', 'size': 272156L},
 {'cdate': '', 'path': '20090831-09.56.plb', 'size': 177219L},
 {'cdate': '', 'path': '20090916-16.24.plb', 'size': 596406L}]
Returns:
  • a list of backups
  • list of dict

ping(self, string='')

Send a command to server to test if it is up.

protocol(self, protocol, strict=False)

Translate protocol name OR number to tuple with name AND number. Can be used to e.g translate numerical protocol in connlog.search() result to protocol name.

An unknown protocol will be translated to e.g '#7' or -1, unless strict is set to True, in which case ValueError is raised for unknown protocols.

Returns:
  • Tuple with name and nr of specified protocol.
  • tuple of (str, int)
Parameters:
  • protocol (int, str or a ProtocolObject Item) - Name or number of an IP protocol
  • strict (bool) - If True, ValueError is raised for an unknown protocol, if False (default), an unknown protocol translates to number -1 or name '#7' (where 7 is the supplied unknown protocol number).

protocols_dict(self)

Returns a dictionary with name:nr and nr:name items for IP protocols. Can be used to e.g translate numerical protocol in connlog.search() result to protocol name.

Returns:
  • Dict with name:nr and nr:name items for IP protocols.
  • dict of str:int and int:str

remove(self, name)

Remove a backup file

>>> b.restore("mybackup.plb")
Parameters:
  • name (str) - Name of backup file

restore(self, name, section='All', systemid='local')

Restore a backup

>>> b.restore("mybackup.plb", "Rules & Object Configuration")
Parameters:
  • name (str) - Name of backup file
  • section (str) - The section in the backup file to restore, such as "Rules & Object Configuration" or "All" for all sections (default).
  • systemid (str) - Systemid to use for the items, or "local" to use system's default, or "file" to use the systemid in file.
Exceptions raised:
  • PLDBUnsupportedInFirmware - If 'systemid' is used in firmware without support.

rollback(self)

Abort the current transaction and discard the data.

This will also automatically happen if your connection drops or that you exit the program without commit.

Exceptions raised:
  • resource.PLDBError - If the rollback command failed.

services_cmd(self, services=[], props=[])

Send services to pldbd

Sets stringtable for services and properties. Do NOT use this unless you know exactly what you are doing.

Parameters:
  • services (list of str) - List of services
  • props (list of str) - List of service properties

services_list(self)

List all services

Returns:
  • List of services
  • list of str

services_prop_list(self)

List all properties.

Returns:
  • List of service properties
  • list of str

take(self, name='', resource='')

Take a new backup.

Creates a new backup of current database contents. The backup will be given the current date and time as name.

>>> b.take()
'20091026-08.15.plb'
Returns:
  • Name of new backup
  • str
Parameters:
  • name (str) - Name of newly created backup file. Requires firmware v12.4 or newer.
  • resource (str) - Include only the specified resource in backup file, use empty string "" to include all resources (default). Requires firmware v12.4 or newer.
Exceptions raised:
  • PLDBUnsupportedInFirmware - If 'name' or 'resource' argument is used without firmware support.

upload(self, fname, data)

Upload a backup

>>> data = file("/tmp/back.plb","rb").read()
>>> len()
596406L
>>> data[:52]
"<?xml version='1.0' encoding='UTF-8'?>\n<PacketLogic "
>>> b.upload("name-on-pl.plb", data)
Parameters:
  • fname (str) - Name of file.
  • data (str) - The contents of the file.

upload_from(self, fname, srcpath)

Upload a backup from a local file.

>>> b.upload_from("name-on-pl.plb", "/tmp/back.plb")
Parameters:
  • fname (str) - Name of file.
  • srcpath (str) - Path to source file

wait_for_commit(self, pinginterval=60)

Wait for new data to be committed on resource.

This method returns as soon as the server signals that another client has committed new data to the resource. It also periodically tests the connection to the server. If connection is broken (or any other error happens) an exception is raised.

Parameters:
  • pinginterval (int) - Interval used to check if connection still is alive.

xfb_flags_list(self)

List all XFB (Transfer Behaviour) flags, that can be used in FlagObjects.

Returns:
  • List of XFB flags
  • list of str

commitid

The CommitID associated with this session. (14.0 or newer only)