ZODB packing and backing up
step-by-step guide to setup ZODB packing and backing up service
The document covers many sides of Zope server maintenance, namely:
- how to setup zope server as a system service (init.d script tuned for local installation),
- how to tune server performance,
- how to control server with POSIX signals,
- names of server log files, format of the files,
- how to organize log files rotation with logrotate service (logrotate.d script tuned for local installation),
- how to pack and backup ZODB automatically,
- how to recover corrupted ZODB;
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/stdoutI entered username:password and pressed ^D three times to encode username:password string and exit uuencode.
begin-base64 644 /dev/stdout
username:passworddXNlcm5hbWU6cGFzc3dvcmQ=
====
>
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!