Last active
September 24, 2025 13:07
-
-
Save tiwiex/b3f5a9a158b5a5cd4c227e4873b0c94f to your computer and use it in GitHub Desktop.
backup_to_git.sh
This file contains hidden or 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 | |
| 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