Changeset 176

Show
Ignore:
Timestamp:
07/02/10 16:12:33 (4 years ago)
Author:
depesz
Message:

new version, handling of different prefixes of logs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/archive_logs.sh

    r139 r176  
    4040             : would archive to files that already exist will get skipped with 
    4141             : warning) 
     42    -p VALUE : prefix of log filename. Defaults to 'postgresql' 
    4243 
    4344Defaults: 
     
    4647Description: 
    4748 
    48 $0 finds all PostgreSQL log files, named: postgresql-YYYY-MM-DD.log or 
    49 postgresql-YYYY-MM-DD_HHMISS.log, skips files that are too new to new 
     49$0 finds all PostgreSQL log files, named: "PREFIX"-YYYY-MM-DD.log or 
     50"PREFIX"-YYYY-MM-DD_HHMISS.log, skips files that are too new to new 
    5051compressed, compressed rest and moves to archive dir. 
    5152 
     
    8889#             : default values are in "MAIN PROGRAM" to simplify finding them 
    8990read_arguments () { 
    90     while getopts ':d:xva:k:c:norh' opt "$@" 
     91    while getopts ':d:xva:k:c:p:norh' opt "$@" 
    9192    do 
    9293        case "$opt" in 
     
    108109            c) 
    109110                COMPRESS="$OPTARG" 
     111                ;; 
     112            p) 
     113                PREFIX="$OPTARG" 
    110114                ;; 
    111115            n) 
     
    155159    fi 
    156160 
     161    if [[ "$PREFIX" == "" ]] 
     162    then 
     163        PREFIX=postgresql 
     164    fi 
    157165    COMPRESS_EXTENSION=$( get_compress_extension ) 
    158166    if [[ "$COMPRESS_EXTENSION" == "" ]] 
     
    246254# Using ls could be an option, but it tends to write messages to STDERR if 
    247255# there are no matching files - not something that we would like. 
    248 find "$LOG_DIRECTORY"/ -type f \( -name 'postgresql-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].log' -o -name 'postgresql-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].log' \) -print | \ 
    249     egrep "^${LOG_DIRECTORY}/postgresql-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](_[0-9][0-9][0-9][0-9][0-9][0-9])?.log" | \ 
     256find "$LOG_DIRECTORY"/ -type f \( -name "${PREFIX}-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].log" -o -name "${PREFIX}-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].log" \) -print | \ 
     257    egrep "^${LOG_DIRECTORY}/${PREFIX}-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](_[0-9][0-9][0-9][0-9][0-9][0-9])?.log" | \ 
    250258    sort | \ 
    251259    while read SOURCE_FILENAME 
     
    253261        FILENAME=$( basename "$SOURCE_FILENAME" ) 
    254262        # skip files that are not older than $BORDER_DATE 
    255         if [[ ! "$FILENAME" < "postgresql-$BORDER_DATE" ]] 
     263        if [[ ! "$FILENAME" < "${PREFIX}-$BORDER_DATE" ]] 
    256264        then 
    257265            continue