#! /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

echo "| Create backup"
RSBACKUP_TODAY=1980-01-01 s ${RSBACKUP} --backup --text got/11.txt --html got/11.html
# volume1: 1980-01-01
# volume2: 1980-01-01
exists logs/1980-01-01-device1-host1-volume1.log
exists logs/1980-01-01-device1-host1-volume2.log
exists logs/1980-01-01-device2-host1-volume1.log
exists logs/1980-01-01-device2-host1-volume2.log
exists store1/host1/volume1/1980-01-01
exists store1/host1/volume2/1980-01-01
exists store2/host1/volume1/1980-01-01
exists store2/host1/volume1/1980-01-01
compare ${srcdir:-.}/expect/11.txt got/11.txt
compare ${srcdir:-.}/expect/11.html got/11.html

echo "| Edit config"
sed < config > config.new 's/^ *volume volume2.*//;s/^ *min-backups 2//'
mv config.new config

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

echo "| Retire volume2"
RSBACKUP_TODAY=1980-01-01 RUN=retire s ${RSBACKUP} --verbose --retire --text got/13.txt --html got/13.html host1:volume2
exists retire-dev-pre.ran
exists retire-dev-post.ran
exists retire-dev-pre.acted
exists retire-dev-post.acted
exists logs/1980-01-01-device1-host1-volume1.log
absent logs/1980-01-01-device1-host1-volume2.log
exists logs/1980-01-01-device2-host1-volume1.log
absent logs/1980-01-01-device2-host1-volume2.log
exists store1/host1/volume1/1980-01-01
absent store1/host1/volume2
exists store2/host1/volume1/1980-01-01
absent store2/host1/volume2
compare ${srcdir:-.}/expect/13.txt got/13.txt
compare ${srcdir:-.}/expect/13.html got/13.html

cleanup
