#!/bin/bash # Creates backups of /storage/docker/ set -e # Define paths and date format DOCKERPATH="/storage" DOCKERDIR="docker" DATE=$(date "+%Y-%m-%d_%H-%M") SUBDIR="${HOME}/compose_backups" mkdir -p ${SUBDIR} # Output the current date for reference echo "Backup Date: $DATE" # Find files within the docker directory up to 3 levels deep and less than 500k in size FILES=$(cd ${DOCKERPATH} && find ${DOCKERDIR} -maxdepth 2 -type f -size -500k) # Assert that files are non-empty if [ -z "$FILES" ]; then echo "No files found to back up." exit 1 fi # Create archive with the form: $(DATE)_$(UNIX_TIME)_dockerfiles_backup.tar.gz ARCHIVE_NAME="compose_backups_${DATE}.tar.gz" # Create the tar archive tar -C ${DOCKERPATH} -czf "${SUBDIR}/${ARCHIVE_NAME}" ${FILES} echo "Backup created: ${ARCHIVE_NAME}"