-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_extract_AC.sh
More file actions
44 lines (33 loc) · 1.04 KB
/
docker_extract_AC.sh
File metadata and controls
44 lines (33 loc) · 1.04 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
#!/bin/bash
# Script for copying modified files from Docker container with directory filtering
# usage: ./extract_changes.sh <container_id> [<target_directory>]
set -euo pipefail
if [ -z "$1" ]; then
echo "Usage: $0 <container_id> [<target_directory>]"
exit 1
fi
CONTAINER_ID="$1"
TARGET_DIR="${2:-/}" # root default
OUTPUT_DIR="./output"
echo "Analyzing changes in $TARGET_DIR..."
changes=$(docker diff "$CONTAINER_ID" | grep -E "^[AC]\s${TARGET_DIR}" | awk '{print $2}')
if [ -z "$changes" ]; then
echo "No changed found."
exit 0
fi
echo "Found changes:"
echo "$changes" | sed 's/^/ /'
echo "Copying files to $OUTPUT_DIR..."
mkdir -p "$OUTPUT_DIR"
while IFS= read -r file; do
# file check (not dir)
if docker exec "$CONTAINER_ID" test -f "$file"; then
dest="$OUTPUT_DIR$file"
mkdir -p "$(dirname "$dest")"
echo " → $file"
docker cp "$CONTAINER_ID:$file" "$dest"
else
echo " Directory skipping: $file"
fi
done <<< "$changes"
echo "The modified files are copied to $OUTPUT_DIR."