#! /bin/sh
# Copyright © 2011, 2012, 2014, 2015, 2017, 2019 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

echo "| --dry-run should do nothing"
RUN=dryrun RSBACKUP_TIME=315532800 s ${RSBACKUP} --dry-run --backup --text ${WORKSPACE}/got/dryrun.txt --html ${WORKSPACE}/got/dryrun.html host1:volume1
exists ${WORKSPACE}/dryrun-dev-pre.ran
exists ${WORKSPACE}/dryrun-dev-post.ran
absent ${WORKSPACE}/dryrun-dev-pre.acted
absent ${WORKSPACE}/dryrun-dev-post.acted
exists ${WORKSPACE}/dryrun-pre.ran
exists ${WORKSPACE}/dryrun-post.ran
absent ${WORKSPACE}/dryrun-pre.acted
absent ${WORKSPACE}/dryrun-post.acted
absent ${WORKSPACE}/store1/host1/volume1/1980-01-01T00:00:00
absent ${WORKSPACE}/store1/host1/volume1/1980-01-01T00:00:00.incomplete
absent ${WORKSPACE}/store1/host1/volume2
absent ${WORKSPACE}/store2/host1
compare ${srcdir:-.}/expect/backup/dryrun.txt ${WORKSPACE}/got/dryrun.txt
compare ${srcdir:-.}/expect/backup/dryrun.html ${WORKSPACE}/got/dryrun.html
absent ${WORKSPACE}/logs/backups.db # not created with --dry-run

echo "| Create backup for one volume"
RUN=volume1 RSBACKUP_TIME=315532800 s ${RSBACKUP} --backup --text ${WORKSPACE}/got/onevolume.txt --html ${WORKSPACE}/got/onevolume.html host1:volume1
exists ${WORKSPACE}/volume1-dev-pre.ran
exists ${WORKSPACE}/volume1-dev-post.ran
exists ${WORKSPACE}/volume1-dev-pre.ran
exists ${WORKSPACE}/volume1-dev-post.ran
exists ${WORKSPACE}/volume1-pre.acted
exists ${WORKSPACE}/volume1-post.acted
exists ${WORKSPACE}/volume1-pre.acted
exists ${WORKSPACE}/volume1-post.acted
compare ${WORKSPACE}/volume1 ${WORKSPACE}/store1/host1/volume1/1980-01-01T00:00:00
absent ${WORKSPACE}/store1/host1/volume1/1980-01-01T00:00:00.incomplete
absent ${WORKSPACE}/store1/host1/volume2
absent ${WORKSPACE}/store1/host1/volume3
absent ${WORKSPACE}/store2/host1/volume2
absent ${WORKSPACE}/store2/host1/volume3
compare ${srcdir:-.}/expect/backup/onevolume.txt ${WORKSPACE}/got/onevolume.txt
compare ${srcdir:-.}/expect/backup/onevolume.html ${WORKSPACE}/got/onevolume.html
exists ${WORKSPACE}/logs/backups.db # default database path

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

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

cleanup
