Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Only Update the 4 Variables Below #
- backupDirectory=/home/kevin/Docker
- backupDestination=/media/Backup/Containers
- tmpDirectory=/media/Backup/tmp
- skipDirs="Portainer Netdata" # (Space-Separated)
- ##################################
- # DO NOT UPDATE THE SCRIPT BELOW #
- ##################################
- # Loop through Container Directories
- for dir in "$backupDirectory"/*/; do
- dir_name=$(basename "$dir")
- # Skip Listed Directories
- if [[ " $skipDirs " =~ " $dir_name " ]]; then
- echo "Skipping $dir_name (owned by root)"
- continue
- fi
- # Get Start Time
- start_time=$(date +%s)
- # Copy Container Directory to Tmp Location
- echo "Copying $dir_name to temporary directory..."
- cp -r "$dir" "$tmpDirectory/"
- # Compress the Copied Container Contents
- echo "Compressing $dir_name..."
- tar -czf "$backupDestination/$dir_name-$(date +%Y%m%d).tar.gz" -C "$tmpDirectory" "$dir_name"
- # Remove the Tmp Copy
- rm -rf "$tmpDirectory/$dir_name"
- # Get End Time
- end_time=$(date +%s)
- # Total Time in Seconds
- elapsed_time=$((end_time - start_time))
- # Calculate Hours, Minutes, Seconds
- hours=$((elapsed_time / 3600))
- minutes=$(( (elapsed_time % 3600) / 60 ))
- seconds=$((elapsed_time % 60))
- # Display Console Message
- echo "Backed up $dir_name in ${hours} Hours ${minutes} Minutes ${seconds} Seconds"
- fi
- done
- # Display Final Console Message
- echo "Backup Completed!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement