-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-db-volume.sh
More file actions
executable file
·40 lines (34 loc) · 1.15 KB
/
export-db-volume.sh
File metadata and controls
executable file
·40 lines (34 loc) · 1.15 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
#!/bin/bash
set -e
VOLUME_NAME="pips-mariadb-data"
OUTPUT_FILE="pips-mariadb-data.tar.gz"
echo "Exporting volume: ${VOLUME_NAME}"
echo "Output file: ${OUTPUT_FILE}"
# Check if volume exists
if ! docker volume inspect ${VOLUME_NAME} > /dev/null 2>&1; then
echo "ERROR: Volume ${VOLUME_NAME} does not exist"
echo "Run 'docker-compose up' first to create and populate the volume"
exit 1
fi
# Export volume to tarball
echo "Creating tarball..."
docker run --rm \
-v ${VOLUME_NAME}:/data:ro \
-v $(pwd):/backup \
alpine \
tar czf /backup/${OUTPUT_FILE} -C /data .
# Get file size
SIZE=$(du -h ${OUTPUT_FILE} | cut -f1)
echo ""
echo "✅ Successfully exported ${VOLUME_NAME}"
echo ""
echo "Output: ${OUTPUT_FILE} (${SIZE})"
echo ""
echo "To import on RHEL9 server:"
echo " # With Docker:"
echo " docker volume create ${VOLUME_NAME}"
echo " docker run --rm -v ${VOLUME_NAME}:/data -v \$(pwd):/backup alpine tar xzf /backup/${OUTPUT_FILE} -C /data"
echo ""
echo " # With Podman (rootless):"
echo " podman volume create ${VOLUME_NAME}"
echo " podman unshare tar xzf ${OUTPUT_FILE} -C ~/.local/share/containers/storage/volumes/${VOLUME_NAME}/_data"