Personal tools
You are here: Home Members zopeadmin scripts zope_pack
Document Actions

zope_pack

script to automate packing and backing up

Click here to get the file

Size 1.7 kB - File type text/x-sh

File contents

#!/bin/bash

# script to pack and back up ZODB
# Author: Alexey Filin

# message about failure
export mess=""

# exit code of failed command
export exit_code=0

# mail address to send message on failure
export admin_address="root@localhost"

# url to pack ZODB
export packing_url="http://localhost:8080/Control_Panel/Database/manage_pack?days:float=7"

# ZODB directory
export zodb_dir="/zope_root_dir/var"

# backup host
export backup_host="myfileserver"

# backup directory
export backup_dir="/archives/zope/ZODB"

function mailAboutFailure {
    if [ "${mess}" != "" ]; then
        mail -s "ERROR: failed to pack and back up ZODB"\
            "${admin_address}" <<EOF
${mess}
EOF
    fi
}


#############################################################################
# check and set environment

comm="su zope"

# redirrect stdin/stdout to log file
exec > /dev/null || {
    exit_code=$?
    mess="\`exec > /dev/null' failed"
    mailAboutFailure
    exit ${exit_code}
}

comm="ping -c 3 -w 100 ${backup_host}"
${comm} || {
    exit_code=$?
    mess="\`${comm}' failed"
    mailAboutFailure
    exit ${exit_code}
}

su zope -s /bin/sh -c 'ls ${backup_dir}' || {
    exit_code=$?
    mess="\`ls ${backup_dir}' failed"
    mailAboutFailure
    exit ${exit_code}
}


#############################################################################
# pack ZODB

su zope -s /bin/sh -c 'wget -O /dev/null --header="Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" "${packing_url}"' || {
    exit_code=$?
    mess="packing failed"
    mailAboutFailure
    exit ${exit_code}
}


# back up ZODB
export suff=`date +%A`
su zope -s /bin/sh -c 'cp ${zodb_dir}/Data.fs.old ${backup_dir}/Data.fs.$suff' || {
    exit_code=$?
    mess="backing up failed"
    mailAboutFailure
    exit ${exit_code}
}
by portal administrator last modified March 18, 2006 at 20:22

Powered by Plone, the Open Source Content Management System