#! /usr/bin/env bash
# Copyright © 2011 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/8.txt --html got/8.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/volume2/1980-01-01
compare ${srcdir:-.}/expect/8.txt got/8.txt
compare ${srcdir:-.}/expect/8.html got/8.html

echo "| Edit config"
sed < config > config.new 's/^device device2//'
mv config.new config

echo "| --dry-run should do nothing"
RSBACKUP_TODAY=1980-01-01 s ${RSBACKUP} --retire-device --dry-run --text got/9.txt --html got/9.html device2
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/volume2/1980-01-01
compare ${srcdir:-.}/expect/9.txt got/9.txt
compare ${srcdir:-.}/expect/9.html got/9.html

echo "| Retire device2"
RSBACKUP_TODAY=1980-01-01 s ${RSBACKUP} --retire-device --text got/10.txt --html got/10.html device2
exists logs/1980-01-01-device1-host1-volume1.log
exists logs/1980-01-01-device1-host1-volume2.log
absent logs/1980-01-01-device2-host1-volume1.log
absent 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/volume2/1980-01-01
compare ${srcdir:-.}/expect/10.txt got/10.txt
compare ${srcdir:-.}/expect/10.html got/10.html

cleanup
