#!/usr/bin/env bash # Unit tests for backup.sh # This tool is NOT intended to be used outside # of a testing environment, please use at your own risk. # By Marco Cetica 2023 () # set -e helper() { cat < /etc/ssh/$file done for file in index.html style.css logic.js ; do head -c 1M /var/www/$file done for file in nginx.conf fastcgi.conf mime.types ; do head -c 1M /etc/nginx/$file done for file in access.log error.log lastlog messages ; do head -c 1M /var/log/$file done } execute_backup() { ./backup.sh -c -b sources.bk "$PWD" badpw } extract_backup() { host="$(uname -n)" date="$(date +'%Y%m%d')" ./backup.sh -c -e "$PWD"/backup-"$host"-"$date".tar.gz.enc badpw "$PWD"/backup-"$host"-"$date".sha256 } test_backup() { for dir in "$PWD/backup.sh.tmp/"backup-*-* ; do if [ ! -d "$dir" ]; then echo "Can't find '$dir' backup!" exit 1 else echo "Found '$dir'" fi done } if [ $# -eq 0 ]; then helper exit 1 fi if [ "$1" = "I_HAVE_READ_THE_HELPER" ]; then if [ "$(id -u)" -ne 0 ]; then echo "Run this tool as root" exit 1 fi create_files execute_backup extract_backup test_backup fi