Re: [Evolution] Backing up.



On Mon, 2004-03-08 at 14:56, Steven Tryon wrote:
[...]
I also have accumulated a large number of cache folders under
~/evolution/mail/pop and pop3, which I assume can be safely cleared
before backing up?
[...]

I have created the following two scripts to backup evolution:
--- bu-evo ---
#!/bin/bash

echo 'shutting down evolution and background processes'

evolution --force-shutdown

echo 'backing up /home/m8ram/evolution/'

/home/m8ram/bin/bu -e -s /home/m8ram/evolution/ -d /data/backup/evolution/

echo 'backing up /home/m8ram/.gconf/apps/evolution/'

/home/m8ram/bin/bu -s /home/m8ram/.gconf/apps/evolution/ -d /data/backup/gconf/
--- bu-evo ---

--- bu ---
#!/bin/bash

SOURCE_DIR=
TARGET_DIR=
PROGNAME=$(basename $0)
VERSION="0.8"

EXT=.tar.bz2
SPLIT=
COUNTER=1

DATE=$(date +'%Y%m%d')          # The name of the backup is in YYYYMMDD-format

BU_EVOLUTION=
EXCLUDELIST=/data/backup/evolution/exclude-index


function error_exit
{
        #####
        #       Function for exit due to fatal program error
        #       Accepts 1 argument
        #               string containing descriptive error message
        #####

        echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2
        exit 1

}


function graceful_exit
{
        #####
        #       Function called for a graceful exit
        #       Tests whether or not the backup was created
        #       No arguments
        #####

        if [ -f ${TARGET_DIR}/${DATE}${SPLIT}${EXT} ]; then
            echo "backup ${TARGET_DIR}/${DATE}${SPLIT}${EXT} created"
            exit
        else
            echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2
            echo "backup ${TARGET_DIR}/${DATE}${SPLIT}${EXT} has not been created"
            exit 1
        fi

}


function signal_exit
{
        #####
        #       Handle termination signals
        #       Arguments:
        #               1       signal spec (required)
        #####

        # Fatal error if required arguments are missing

        if [ "bu" = "" ]; then
                error_exit "signal_exit: missing argument 1"
        fi

        case bu in
                INT)    echo "bu: Aborted by user" # TODO call int_exit?
                        exit
                        ;;
                TERM)   echo "bu: Terminated" # TODO call term_exit?
                        exit
                        ;;
                *)      error_exit "Terminated on unknown signal"
                        ;;
        esac

}       # end of signal_exit


function term_exit
{
        #####
        #       Function to perform exit if termination signal is trapped
        #       No arguments
        #####

        echo "${PROGNAME}: Terminated"
        graceful_exit
}


function int_exit
{
        #####
        #       Function to perform exit if interrupt signal is trapped
        #       No arguments
        #####

        echo "${PROGNAME}: Aborted by user"
        exit
}


function usage
{
        #####
        #       Function to display usage message (does not exit)
        #       No arguments
        #####

        echo "Usage: ${PROGNAME}"
# this still needs to be written properly

}


function helptext
{
        #####
        #       Function to display help message for program
        #       No arguments
        #####

        echo "Usage: ${PROGNAME}"
# this still needs to be written properly

}       


function test_source
{
        #####
        #       Function to check that source directory exists
        #       No arguments
        #####

        if [ ! -d ${SOURCE_DIR} ]; then
                echo "Source directory ${SOURCE_DIR} does not exist!" 1>&2
                exit 1
        fi
}


function test_target
{
        #####
        #       Function to check that target directory exists, and create it if it does not
        #       No arguments
        #####

        if [ ! -d ${TARGET_DIR} ]; then
                echo "Target directory ${TARGET_DIR} does not exist!" 1>&2
                echo "Creating ${TARGET_DIR}" 1>&2
                mkdir -p ${TARGET_DIR}
        fi

}


function bu_normal
{
        #####
        #       Function to perform the actual backup
        #       No arguments
        #####

        echo "Creating backup of ${SOURCE_DIR}"
        tar -cjf ${TARGET_DIR}/${DATE}${SPLIT}${EXT} ${SOURCE_DIR}
        graceful_exit

}

function bu_evolution
{
        #####
        #       Function to perform the actual backup
        #       first check if the file already exists
        #       exclude 'mbox.*'
        #       No arguments
        #####

        if [ -f ${EXCLUDELIST} ]; then
            echo "Creating backup of ${SOURCE_DIR}"
            tar --exclude-from=${EXCLUDELIST} -cjf ${TARGET_DIR}/${DATE}${SPLIT}${EXT} ${SOURCE_DIR}
            graceful_exit
        else
            echo "${EXCLUDELIST} does not exist!"
            echo "NO BACKUP CREATED!!!"
            echo "Create the file ${EXCLUDELIST} by running:"
            echo "find ${SOURCE_DIR} -name "mbox.*" > ${EXCLUDELIST}"
            echo "and rerun ${PROGNAME}"
            exit 1
        fi

}


###########################################################################
#       Program starts here
###########################################################################

##### Command Line Processing #####

while [ "$1" != "" ]; do
    case $1 in
        -s | --source )         shift
                                SOURCE_DIR=$1
                                ;;
        -d | --destination )    shift
                                TARGET_DIR=${1%/}
                                ;;
        -e | --evolution )      BU_EVOLUTION=1
                                ;;
        -h | --help )           helptext
                                graceful_exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done


##### Main Logic #####

test_source

test_target

# Perform the backup: check if backup already exists

while [ $COUNTER -lt 10 ]; do
        if [ -f ${TARGET_DIR}/${DATE}${SPLIT}${EXT} ]; then
                echo "you already created a backup today! ${TARGET_DIR}${DATE}${SPLIT}${EXT}"
                echo "creating extra backup..."
                COUNTER=$((COUNTER + 1))
                SPLIT=-${COUNTER}
        else
            if [ "$BU_EVOLUTION" = "1" ]; then
                bu_evolution
            else
                bu_normal
            fi

            COUNTER=10
            exit
        fi
done

graceful_exit
--- bu ---

This backs up all the important stuff but leaves out the
(space-consuming) index-files...

HTH
-- 
# Mertens Bram "M8ram"   <bram-mertens linux be>     Linux User #249103 #
# SuSE Linux 8.2 (i586) kernel 2.4.20-4GB      i686                256MB RAM #
#          8:32pm  up   3:40,  2 users,  load average: 0.15, 0.08, 0.03 #




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]