#!/usr/bin/env bash # 2024-01-29 Hyperling # Create a backup file with a generic name for polling. DIR="$(dirname -- "${BASH_SOURCE[0]}")" PROG="$(basename -- "${BASH_SOURCE[0]}")" echo "$DIR/$PROG" source $DIR/../source.env ## Variables ## TAG="Docker" DATE="`date "+%Y%m%d-%H%M%S"`" BACKUP_DIR="/srv/backups" BASENAME="$BACKUP_DIR/Backup" file="$BASENAME.$DATE.$HOSTNAME.$TAG.zip" time="`which time`" ## Main ## # Ensure backup directory exists with correct permissions. mkdir -pv $BACKUP_DIR chmod -Rv 755 $BACKUP_DIR chown -Rv root:root $BACKUP_DIR # Remove the last backup. echo "`date` - Removing existing files." rm -fv "$BASENAME"*"$TAG"* echo -e "\n`date` - Take down services for a cold backup." manage.sh -d echo -e "\n`date` - Create the backup for '$DOCKER_HOME'." $time zip -r $file.tmp \ $DOCKER_HOME \ /etc/crontab /etc/cron.d /var/spool/cron \ /var/{log,mail} 1>/dev/null mv -v $file.tmp $file echo -e "\n`date` - Done with zipping, check size." ls -sh $file echo -e "\n`date` - Ensure other users can access the file." chmod -v 755 $file echo -e "\n`date` - Bring services back up." manage.sh -u ## Finish ## echo -e "\n`date` - Done!" exit 0