trixie/roles/exam_homes/files/archive-homes

24 lines
523 B
Text
Raw Normal View History

2022-10-22 16:44:05 +02:00
#!/usr/bin/bash
#
# Backup and remove all student home directories.
set -eu
HDIRS='/home/'
DIRS=()
for DIR in $(find $HDIRS -maxdepth 1 -mindepth 1 -type d) ; do
H="$(basename $DIR)"
if [[ "$H" =~ ^L_ ]] || [[ "$H" =~ ansible ]] ; then
echo "Skipping home of '$H'."
continue
fi
DIRS+=("$DIR")
done
[[ "${#DIRS[@]}" -eq 0 ]] && exit 0
tar czf "/var/backups/homes_$(date -I).tar.gz" -C "$HDIRS" \
-P --transform="s%$HDIRS%%" "${DIRS[@]}"
rm -rf "${DIRS[@]}"
echo "Archived and removed: ${DIRS[@]}"