#! /usr/bin/env bash
# Copyright © 2011, 2012 Richard Kettlewell.
#
# This program is 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 3 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, see <http://www.gnu.org/licenses/>.
set -e
. ${srcdir:-.}/setup.sh

setup

export EXPECT_STATUS=ok

echo "| --dry-run should do nothing"
RUN=dryrun RSBACKUP_TODAY=1980-01-01 s ${RSBACKUP} --dry-run --backup --text got/15.txt --html got/15.html host1:volume1
exists dryrun-dev-pre.ran
exists dryrun-dev-post.ran
absent dryrun-dev-pre.acted
absent dryrun-dev-post.acted
#exists dryrun-pre.ran
#exists dryrun-post.ran
absent dryrun-pre.acted
absent dryrun-post.acted
absent store1/host1/volume1/1980-01-01
absent store1/host1/volume2
absent store2/host1
compare ${srcdir:-.}/expect/15.txt got/15.txt
compare ${srcdir:-.}/expect/15.html got/15.html

echo "| Create backup for one volume"
RUN=volume1 RSBACKUP_TODAY=1980-01-01 s ${RSBACKUP} --backup --text got/16.txt --html got/16.html host1:volume1
exists volume1-dev-pre.ran
exists volume1-dev-post.ran
exists volume1-dev-pre.ran
exists volume1-dev-post.ran
exists volume1-pre.acted
exists volume1-post.acted
exists volume1-pre.acted
exists volume1-post.acted
compare volume1 store1/host1/volume1/1980-01-01
absent store1/host1/volume2
absent store1/host1/volume3
absent store2/host1/volume2
absent store2/host1/volume3
compare ${srcdir:-.}/expect/16.txt got/16.txt
compare ${srcdir:-.}/expect/16.html got/16.html

echo "| Create backup for one host"
RUN=host1 RSBACKUP_TODAY=1980-01-02 s ${RSBACKUP} --backup --text got/17.txt --html got/17.html host1
exists host1-pre.acted
exists host1-post.acted
compare volume1 store1/host1/volume1/1980-01-02
compare volume2 store1/host1/volume2/1980-01-02
absent store1/host1/volume3
compare volume3 store2/host1/volume3/1980-01-02
compare ${srcdir:-.}/expect/17.txt got/17.txt
compare ${srcdir:-.}/expect/17.html got/17.html

echo "| Create backup for everything"
RUN=all RSBACKUP_TODAY=1980-01-03 s ${RSBACKUP} --backup --text got/18.txt --html got/18.html
exists all-pre.acted
exists all-post.acted
compare volume1 store1/host1/volume1/1980-01-03
compare volume2 store1/host1/volume2/1980-01-03
absent store1/host1/volume3
compare volume3 store2/host1/volume3/1980-01-03
compare ${srcdir:-.}/expect/18.txt got/18.txt
compare ${srcdir:-.}/expect/18.html got/18.html

cleanup
