Skip to content

Instantly share code, notes, and snippets.

@mrl22
Created August 23, 2023 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrl22/1f2f13d00b3176815abc0bd9c9aad08a to your computer and use it in GitHub Desktop.
Save mrl22/1f2f13d00b3176815abc0bd9c9aad08a to your computer and use it in GitHub Desktop.
Borg Backup Server - Compact All Repositories
#!/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