Personal tools
You are here: Home Members zopeadmin guides & specs administration ZODB packing and backing up
Document Actions

ZODB packing and backing up

by portal administrator last modified July 18, 2006 at 17:19

step-by-step guide to setup ZODB packing and backing up service

The document covers many sides of Zope server maintenance, namely:

Unfortunately packing with ZMI is described without authorization on the side of zope server, so a hack is required to provide it. Authorization on the side of web-server (Zope is one of them) is performed with data sent in header of http-request, corresponding field in header is to contain something like:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
where third string in the line above is credential. The credential is base64-encoded username and password separated by colon. Encoding can be done with uuencode utility being run with -m option:
> uuencode -m /dev/stdout
begin-base64 644 /dev/stdout
username:passworddXNlcm5hbWU6cGFzc3dvcmQ=
====
>
I entered username:password and pressed ^D three times to encode username:password string and exit uuencode.

Instead of python script from the document above used to pack ZODB we can send http request to local Zope server with wget utility which provides options to set required header and redirect answer from Zope server to /dev/null:
wget -O /dev/null --header="Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" 'http://localhost:8080/Control_Panel/Database/manage_pack?days:float=7'
Request is sent to localhost so encryption is not required.

I wrote a script (here is its template) which sends request to pack ZODB and then saves not packed version to archive storage. Packing removes versions of objects of seven days old. Backing up saves versions of ZODB for each weekday, so there is two-week old history of each ZODB object at any time.

'chmod +x' the script then 'chmod go-rwx' it to forbid all other users any access to the file because it contains password to ZMI and put the script into /etc/cron.daily/ directory to run it nightly.

If you run ZODB packing on a multiuser host you have to take care about security and hide credential (else it can be viewed e.g. by ps command during exection) e.g. in script packZODB.py:
#!/usr/bin/python
import sys, urllib

url = "http://localhost:8080/Control_Panel/Database/manage_pack?days:float=0"

class MyUrlOpener( urllib.FancyURLopener ) :
def prompt_user_passwd( self, host, realm ) :
return ( 'username', 'password' )

try:
opener = MyUrlOpener()
opener.open( url )
except IOError:
print "Cannot open URL %s, aborting" % url

`chmod +x' it and change command to pack ZODB in the template script above to:

su zope -s /bin/sh -c '/path/to/script/packZODB.py' || {

That's all, folks!


Powered by Plone, the Open Source Content Management System