Salt
6440710a3e
Unless I make these playbook-wide variables, there's no real way to configure them at runtime. Best to just hardcode them, I suppose
44 lines
879 B
Bash
44 lines
879 B
Bash
#! /bin/bash
|
|
#
|
|
# backup.sh
|
|
# General-purpose backup script that accepts subtasks
|
|
# Copyright (C) 2020 Vintage Salt <rehashedsalt@cock.li>
|
|
#
|
|
# Distributed under terms of the MIT license.
|
|
#
|
|
|
|
set -e
|
|
|
|
export BACKUPSDIR="/backups"
|
|
export MODULESDIR="/opt/backups/modules"
|
|
export DATE="$(date -Iseconds)"
|
|
|
|
# Helper functions
|
|
log() {
|
|
[ -z "$1" ] && return 1
|
|
printf "$(date -Iseconds): $1\n"
|
|
}
|
|
|
|
# Do the do
|
|
if ! [ -d "$BACKUPSDIR" ]; then
|
|
log "Unable to find backups directory: $BACKUPSDIR"
|
|
exit 1
|
|
fi
|
|
if ! [ -d "$MODULESDIR" ]; then
|
|
log "Unable to find modules directory: $MODULESDIR"
|
|
exit 2
|
|
fi
|
|
log "Beginning backups"
|
|
for file in "$MODULESDIR"/*; do
|
|
# Just keep going if we don't have any tasks to do
|
|
[ -f "$file" ] || continue
|
|
# Execute the module and alert if it fails
|
|
log "Executing module: $file"
|
|
(
|
|
source "$file"
|
|
) || {
|
|
log "Error executing module: $file"
|
|
}
|
|
done
|
|
|