j0h

mcp_backfill.sh

j0h
Jun 10th, 2026
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3.  
  4. BASE="/home/mcp/logs"
  5. START_DATE="20260401"
  6.  
  7. # 7 GB reserve margin, in MiB
  8. RESERVE_MB=7168
  9.  
  10. # File you supply for duplication
  11. TMPFILE="/path/to/source/file.csv"
  12.  
  13. # Output filename inside each dated log folder
  14. OUTFILE="file.csv"
  15.  
  16. if [[ ! -f "$TMPFILE" ]]; then
  17. echo "Missing TMPFILE: $TMPFILE"
  18. exit 1
  19. fi
  20.  
  21. current="$START_DATE"
  22.  
  23. while true; do
  24. current=$(date -d "${current} -1 day" +%Y%m%d)
  25.  
  26. year=$(date -d "$current" +%Y)
  27. month=$(date -d "$current" +%-m)
  28. day=$(date -d "$current" +%-d)
  29.  
  30. dir="$BASE/$year/$month/$day"
  31. mkdir -p "$dir"
  32.  
  33. free_kb=$(df --output=avail "$BASE" | tail -n 1)
  34. free_mb=$((free_kb / 1024))
  35.  
  36. usable_mb=$((free_mb - RESERVE_MB))
  37. if (( usable_mb <= 0 )); then
  38. echo "Stopping: reserve margin reached. Free=${free_mb}MB Reserve=${RESERVE_MB}MB"
  39. break
  40. fi
  41.  
  42. outfile="$dir/$OUTFILE"
  43.  
  44. echo "Writing $outfile"
  45. cp "$TMPFILE" "$outfile"
  46. done
  47.  
  48. echo "Done."
  49.  
Advertisement
Add Comment
Please, Sign In to add comment