-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathpreserve_local_data.sh
More file actions
79 lines (71 loc) · 2.02 KB
/
preserve_local_data.sh
File metadata and controls
79 lines (71 loc) · 2.02 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
#!/bin/bash
# Preserve Local Data Files Script
# This script backs up and restores local runtime data files that should never be pushed to GitHub
BACKUP_DIR=".local_backup"
DATA_DIR="data"
# Files to preserve (runtime data that should stay local)
PRESERVE_FILES=(
"$DATA_DIR/ragnar.db"
"$DATA_DIR/livestatus.csv"
"$DATA_DIR/netkb.csv"
"$DATA_DIR/pwnagotchi_status.json"
)
backup_files() {
echo "🔒 Backing up local data files..."
mkdir -p "$BACKUP_DIR"
for file in "${PRESERVE_FILES[@]}"; do
if [ -f "$file" ]; then
cp -p "$file" "$BACKUP_DIR/$(basename $file)"
echo " ✓ Backed up: $file"
fi
done
echo "✅ Backup complete"
}
restore_files() {
echo "♻️ Restoring local data files..."
for file in "${PRESERVE_FILES[@]}"; do
backup_file="$BACKUP_DIR/$(basename $file)"
if [ -f "$backup_file" ]; then
mkdir -p "$(dirname $file)"
cp -p "$backup_file" "$file"
echo " ✓ Restored: $file"
fi
done
echo "✅ Restore complete"
}
cleanup_backup() {
if [ -d "$BACKUP_DIR" ]; then
rm -rf "$BACKUP_DIR"
echo "🧹 Cleaned up backup directory"
fi
}
case "$1" in
backup)
backup_files
;;
restore)
restore_files
;;
cleanup)
cleanup_backup
;;
help|--help|-h)
echo "Usage: $0 {backup|restore|cleanup}"
echo ""
echo "Commands:"
echo " backup - Backup local data files before git pull/update"
echo " restore - Restore local data files after git pull/update"
echo " cleanup - Remove backup directory"
echo ""
echo "Recommended workflow:"
echo " ./preserve_local_data.sh backup"
echo " git pull"
echo " ./preserve_local_data.sh restore"
echo " ./preserve_local_data.sh cleanup"
;;
*)
echo "Error: Invalid command"
echo "Run '$0 help' for usage information"
exit 1
;;
esac