-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexport_group.sh
More file actions
51 lines (39 loc) · 1.56 KB
/
export_group.sh
File metadata and controls
51 lines (39 loc) · 1.56 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
#!/usr/bin/env bash
# export_group.sh - Export Pattern group via cron
# Usage: ./export_group.sh <config_path> <group_string> <output_dir>
set -e
# Check if all required arguments are provided
if [ $# -ne 3 ]; then
echo "Usage: $0 <config_path> <group_string> <output_dir>" >&2
echo "Example: $0 /path/to/config.toml 'Cluster A' /path/to/backups" >&2
exit 1
fi
CONFIG_PATH="$1"
GROUP_STRING="$2"
OUTPUT_DIR="$3"
# Validate config file exists
if [ ! -f "$CONFIG_PATH" ]; then
echo "Error: Config file '$CONFIG_PATH' not found" >&2
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Generate original filename (group string with spaces -> hyphens, case preserved)
ORIGINAL_FILENAME=$(echo "$GROUP_STRING" | tr ' ' '-').car
# Generate timestamped filename
TIMESTAMP=$(date +%s)
TIMESTAMPED_FILENAME=$(echo "$GROUP_STRING" | tr ' ' '-')_${TIMESTAMP}.car
FINAL_OUTPUT_PATH="$OUTPUT_DIR/$TIMESTAMPED_FILENAME"
# Run the cargo command (it will create the original filename)
cargo run --bin pattern-cli -- -c "$CONFIG_PATH" export group "$GROUP_STRING"
# Move the original file to the timestamped name in the output directory
if [ -f "$ORIGINAL_FILENAME" ]; then
mv "$ORIGINAL_FILENAME" "$FINAL_OUTPUT_PATH"
else
echo "Error: Expected output file '$ORIGINAL_FILENAME' not found" >&2
exit 1
fi
# Delete backups older than 7 days - I haven't tested this part yet.
# find "$OUTPUT_DIR" -name "*_*.car" -type f -mtime +7 -delete
echo "Export completed: $FINAL_OUTPUT_PATH"
# echo "Cleaned up backups older than 7 days from: $OUTPUT_DIR"