-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmanage_checkpoint.sh
More file actions
executable file
·99 lines (83 loc) · 3.26 KB
/
manage_checkpoint.sh
File metadata and controls
executable file
·99 lines (83 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Script to manage checkpoint files for data processing
# Usage:
# ./manage_checkpoint.sh list - List all checkpoint files
# ./manage_checkpoint.sh view <file> - View checkpoint details
# ./manage_checkpoint.sh delete <file> - Delete a checkpoint file
# ./manage_checkpoint.sh clean - Delete all checkpoint files
# ./manage_checkpoint.sh stats - Show statistics about checkpoints
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
DATA_DIR="$PROJECT_DIR/data/unprocessed"
case "${1:-}" in
list)
echo "=== Checkpoint files found ==="
find "$DATA_DIR" -name "*.checkpoint" 2>/dev/null || echo "No checkpoint files found"
;;
view)
if [ -z "$2" ]; then
echo "Error: Please provide checkpoint file path"
echo "Usage: $0 view <checkpoint_file>"
exit 1
fi
if [ ! -f "$2" ]; then
echo "Error: Checkpoint file not found: $2"
exit 1
fi
echo "=== Checkpoint details for: $2 ==="
cat "$2" | python3 -m json.tool
;;
delete)
if [ -z "$2" ]; then
echo "Error: Please provide checkpoint file path"
echo "Usage: $0 delete <checkpoint_file>"
exit 1
fi
if [ ! -f "$2" ]; then
echo "Error: Checkpoint file not found: $2"
exit 1
fi
rm -f "$2"
echo "Checkpoint file deleted: $2"
;;
clean)
echo "=== Cleaning all checkpoint files ==="
count=$(find "$PROJECT_DIR" -name "*.checkpoint" 2>/dev/null | wc -l)
if [ "$count" -eq 0 ]; then
echo "No checkpoint files found"
else
find "$PROJECT_DIR" -name "*.checkpoint" -delete 2>/dev/null
echo "All $count checkpoint files have been deleted"
fi
;;
stats)
echo "=== Checkpoint Statistics ==="
echo ""
# Count by type
dila_count=$(find "$DATA_DIR" -name "*.tar.gz.checkpoint" 2>/dev/null | wc -l)
csv_count=$(find "$DATA_DIR" -name "*.csv.checkpoint" 2>/dev/null | wc -l)
json_count=$(find "$DATA_DIR" -name "*.json.checkpoint" 2>/dev/null | wc -l)
total_count=$(find "$PROJECT_DIR" -name "*.checkpoint" 2>/dev/null | wc -l)
echo "Total checkpoints: $total_count"
echo " - DILA archives (.tar.gz): $dila_count"
echo " - Data.gouv files (.csv): $csv_count"
echo " - Directories/Sheets (.json): $json_count"
echo ""
if [ "$total_count" -gt 0 ]; then
echo "Recent checkpoints:"
find "$PROJECT_DIR" -name "*.checkpoint" -exec ls -lh {} \; 2>/dev/null | tail -5
fi
;;
*)
echo "Usage: $0 {list|view|delete|clean|stats} [file]"
echo ""
echo "Commands:"
echo " list - List all checkpoint files"
echo " view <file> - View checkpoint details"
echo " delete <file> - Delete a specific checkpoint file"
echo " clean - Delete all checkpoint files"
echo " stats - Show statistics about checkpoints"
exit 1
;;
esac