Am 20.04.2010 22:49, schrieb Stefan G. Weichinger:
> 
> I'd like to have a script that generates include-lists for amanda-DLEs
> ... the script should accept a parameter defining the overall size of
> the DLE.

See my draft (thanks, Jon, for your suggestions and corrections).

What it does:

* reads in directory, creates include-lists for DLEs smaller than size
defined in script.

What it does not do (yet):

* create additional DLEs when things change:

in my case, video-files are added, so it would make sense to create a
new DLE for the new video-files and let the old/existing include-files
untouched.

* create actual DLE-definitions to copy into disklist

* other stuff (error-checking etc ...)

It's a DRAFT!

:-)

----------------------------

#! /bin/bash
#
####################################################################################################
#
# NAME:                 am_create_sized_dles.sh
#
# April, 22nd, 2010     first draft by Stefan G. Weichinger
#                       corrections by Jon LaBadie
#
# PURPOSE:
#
# read in files of given directory, and generate several text-files for
use as
# so-called include-lists with the amanda backup suite
#
# each include-list contains only files summing up to less than a given
target-size
# so that all the files in one list should fit nicely on one target tape
#
# the initial problem to solve was to fully backup a
mythtv-backend-server, which holds hundreds of
# video files. these get deleted and created in a very dynamic way, so
it was necessary to
# generate fitting include-lists for every run
#
# USAGE: /usr/local/bin/am_create_sized_dles.sh DIRECTORY AMANDA-config
#
# generates include-files into /etc/amanda/CONFIG/includes
#
# which can be used in your DLE via
#
# TODO
#
####################################################################################################

### initialization

# initial size of include-list
SIZE_LIST=0

# suffix starts with 0
FILE_SUFFIX=0

FILE_PREFIX="include"

# remove existing output-files
rm /tmp/$FILE_PREFIX.* 2> /dev/null
rm /tmp/checklist      2> /dev/null

# maximum size of one DLE
# TARGET_DLE_SIZE=100000000 # 100 GB
TARGET_DLE_SIZE=100000000

CONFIG="$1"
INCLUDES_DIR="/etc/amanda/$CONFIG/includes"
SOURCEDIR="$2"
DLE_NAME=${SOURCEDIR//\//_}
SIZE_OVERALL=`du -s $SOURCEDIR`

#################################

# save and change IFS
OLDIFS=$IFS
IFS=$'\n'

## read all files and their sizes into an array

DIR_CONTENT=( $(du -k $SOURCEDIR/*))

# restore it
IFS=$OLDIFS

# get length of an array
tlen=${#dir_conte...@]}

# use for loop read all filenames
for (( i=0; i<${tLen}; i++ ))

do

# extract size
SIZE_ELEMENT="${DIR_CONTENT[$i]%%[ $'\t']*}"

# extract name
NAME_ELEMENT=${DIR_CONTENT[$i]#*[ $'\t']}

# extract only the filename without leading path
NAME_ELEMENT=${NAME_ELEMENT##*/}

# debug: generate one file containing all lines for cross-check
echo $NAME_ELEMENT >> /tmp/checklist

# sum up the size so far
let "SIZE_LIST=$SIZE_LIST+$SIZE_ELEMENT"

if (( SIZE_LIST + SIZE_ELEMENT <= TARGET_DLE_SIZE ))
        then
((SIZE_LIST+=SIZE_ELEMENT))
        echo "./$NAME_ELEMENT" >> /tmp/$FILE_PREFIX.$DLE_NAME.$FILE_SUFFIX
        else
# start next list: increase suffix, echo filename into new list
# reset size-counter
        let "FILE_SUFFIX += 1"
        echo "./$NAME_ELEMENT" >> /tmp/$FILE_PREFIX.$DLE_NAME.$FILE_SUFFIX
        SIZE_LIST=$SIZE_ELEMENT
        fi

        done

        cp /tmp/$FILE_PREFIX.* $INCLUDES_DIR

        exit

Reply via email to