Skip to content

Instantly share code, notes, and snippets.

@tiwiex
Last active September 24, 2025 13:07
Show Gist options
  • Save tiwiex/b3f5a9a158b5a5cd4c227e4873b0c94f to your computer and use it in GitHub Desktop.
Save tiwiex/b3f5a9a158b5a5cd4c227e4873b0c94f to your computer and use it in GitHub Desktop.
backup_to_git.sh
#!/bin/bash
bash backup_frappe_zip.sh "$@"
backup_dir="$HOME/frappe-backups"
max_cycles=5
log_file="$backup_dir/backup.log"
cd "$backup_dir" || exit 1
echo "πŸ” Managing Git backup cycles at $(date)" | tee -a "$log_file"
# Group all zip files by site
declare -A site_zips
# Find all _all.zip files
for file in *_all.zip; do
[ -f "$file" ] || continue
# Extract site name from filename (compatible method)
site_name=$(echo "$file" | sed 's/^[0-9]\{8\}_[0-9]\{6\}-//' | sed 's/_all\.zip$//')
site_zips["$site_name"]+="$file "
done
# Cycle and clean per site
for site in "${!site_zips[@]}"; do
# Convert to array and sort by filename (newest first due to timestamp)
files=(${site_zips[$site]})
sorted=($(printf '%s\n' "${files[@]}" | sort -r))
count=${#sorted[@]}
if (( count > max_cycles )); then
echo "πŸ—‘ Cleaning up old zips for $site..." | tee -a "$log_file"
for ((i=max_cycles; i<count; i++)); do
git rm -f "${sorted[$i]}"
echo " ➀ Deleted ${sorted[$i]}" | tee -a "$log_file"
done
else
echo "ℹ️ $site: $count backups (within limit)" | tee -a "$log_file"
fi
done
# Commit to Git
git add *_all.zip
git add backup.log backup_frappe_zip.sh backup_to_git_zip.sh
git commit -m "πŸ”„ Committed latest backup zips on $(date '+%Y-%m-%d %H:%M:%S')" >> "$log_file" 2>&1
git push origin frappe-live >> "$log_file" 2>&1
echo "βœ… Git backup cycle completed at $(date)" | tee -a "$log_file"
bash backup_lms.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment