#!/usr/bin/bash
#
# Simple collector of storage log files
#
# Copyright (c) 2020-2021 Virtuozzo International GmbH. All rights reserved.
#
# This file is part of vzreport. It's free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Our contact details: Virtuozzo International GmbH, Vordergasse 59, 8200
# Schaffhausen, Switzerland.
#

REPORT_DIR=$1
if [ -z "$REPORT_DIR" ]; then
    echo "Usage: $0 <REPORT_DIR>"
    exit 0
fi

[ -d /var/log/vstorage ] || exit 0

if [ -z $FULL_REPORT ]; then
    LOGFILES=`find /var/log/vstorage -type f | grep -v 'log.[[:digit:]]\|[[:digit:]].blog\|lck\|tail' 2>/dev/null`
else
    LOGFILES=`find /var/log/vstorage -type f 2>/dev/null`
fi

for i in $LOGFILES; do
    if [ -f "$i" ]; then
        archive_name=`echo $i | sed 's#/var/log/vstorage/##'`
        [ -d "$REPORT_DIR/vstorage/"`dirname $archive_name` ] || mkdir -p "$REPORT_DIR/vstorage/"`dirname $archive_name`
        cp "$i" "$REPORT_DIR/vstorage/"`dirname $archive_name`
    fi
done
