Created
August 23, 2023 12:27
-
-
Save mrl22/1f2f13d00b3176815abc0bd9c9aad08a to your computer and use it in GitHub Desktop.
Borg Backup Server - Compact All Repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Loop through user directories in /home/ | |
for user_dir in /home/*; do | |
if [ -d "$user_dir" ]; then | |
user=$(basename "$user_dir") # Extract the username from the path | |
# Check if there is a Borg repo | |
if [ -f "$user_dir/repo/transactions" ]; then | |
usage=$(du -sh "$user_dir/repo" | cut -f1) | |
echo -n "Compacting $user ($usage) ... " | |
su -c "borg compact $user_dir/repo" $user | |
usage=$(du -sh "$user_dir/repo" | cut -f1) | |
echo "DONE! ($usage)" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment