Skip to content

Commit 7149643

Browse files
authored
Update PVC migration script (#1345)
1 parent c1054e6 commit 7149643

4 files changed

Lines changed: 51 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
### Changed
99
- Nexus storage change ([#1341](https://github.com/opendevstack/ods-core/issues/1341))
10+
- Update PVC migration script, adding threads to rsync execution ([#1345](https://github.com/opendevstack/ods-core/pull/1345))
1011
- Update Aqua cli to 760 ([#1344](https://github.com/opendevstack/ods-core/pull/1344))
1112

13+
1214
### Fixed
1315

1416

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ backup-sonarqube:
196196

197197

198198
# PVC MIGRATION
199-
## Migrate data from one PVC to another.
199+
## Migrate data from one PVC to another. Options: SOURCE_PVC, TARGET_PVC, THREADS (default: 5), CPU_REQUEST (default: 1), MEMORY (default: 2)
200200
migrate-pvc-data:
201-
./scripts/migrate_pvc_data.sh --source-pvc $(SOURCE_PVC) --target-pvc $(TARGET_PVC) --namespace $(ODS_NAMESPACE)
201+
./scripts/migrate_pvc_data.sh --source-pvc $(SOURCE_PVC) --target-pvc $(TARGET_PVC) --namespace $(ODS_NAMESPACE) --threads $(THREADS) --cpu $(CPU_REQUEST) --memory $(MEMORY)
202202
.PHONY: migrate-pvc-data
203203

204204

docs/modules/administration/pages/pvc-migration.adoc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ To migrate data between PVCs, follow these steps:
1616

1717
[source,sh]
1818
----
19-
make migrate-pvc-data SOURCE_PVC=<source-pvc-name> TARGET_PVC=<target-pvc-name>
19+
make migrate-pvc-data SOURCE_PVC=<source-pvc-name> TARGET_PVC=<target-pvc-name> [THREADS=<num-threads>] [CPU_REQUEST=<num-cpu>] [MEMORY=<memory-in-gb>]
2020
----
2121

22-
Replace `<source-pvc-name>`, and `<target-pvc-name>` with the appropriate values for your environment.
22+
Replace `<source-pvc-name>`, `<target-pvc-name>`, `<num-threads>`, `<num-cpu>`, and `<memory-in-gb>` with the appropriate values for your environment.
23+
- `THREADS` (optional): Number of parallel threads to use for migration (default: 5).
24+
- `CPU_REQUEST` (optional): Number of CPU cores to request for the migration pod (default: 1).
25+
- `MEMORY` (optional): Memory request and limit in Gigabytes for the migration pod (default: 2).
2326

2427
== Details
2528

26-
- The migration process creates a temporary pod that uses `rsync` to copy data from the source PVC to the target PVC.
27-
- Logs of the migration are stored in `/tmp/target/rsync.log` within the target PVC.
28-
- After the migration, verify the data integrity and delete the temporary pod if necessary.
29+
- The migration process creates a temporary pod that uses parallelized `rsync` to copy data from the source PVC to the target PVC.
30+
- You can control the number of parallel threads and CPU/memory resources via the `THREADS`, `CPU_REQUEST`, and `MEMORY` options.
31+
- After the migration, verify the data integrity and delete the temporary pod.

scripts/migrate_pvc_data.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22

3-
# Exit on error is removed to allow the script to continue on failure
4-
# set -e
5-
63
# Function to display usage
74
usage() {
85
printf "Migrate data from one PVC to another within the OpenShift cluster.\n\n"
@@ -13,6 +10,9 @@ usage() {
1310
printf "\t-s|--source-pvc\t\tName of the source PVC\n"
1411
printf "\t-t|--target-pvc\t\tName of the target PVC\n"
1512
printf "\t-n|--namespace\t\tNamespace where the PVCs are located\n"
13+
printf "\t-p|--threads\t\tNumber of parallel threads (default: 10)\n"
14+
printf "\t-c|--cpu\t\tNumber of CPU cores to request in cores (default: 2)\n"
15+
printf "\t-m|--memory\tMemory request and limit in Gigabytes (default: 5)\n"
1616
}
1717

1818
# Parse arguments
@@ -26,11 +26,25 @@ while [[ "$#" -gt 0 ]]; do
2626
-t=*|--target-pvc=*) TARGET_PVC="${1#*=}" ;;
2727
-n|--namespace) NAMESPACE="$2"; shift ;;
2828
-n=*|--namespace=*) NAMESPACE="${1#*=}" ;;
29+
-p|--threads) THREADS="$2"; shift ;;
30+
-p=*|--threads=*) THREADS="${1#*=}" ;;
31+
-c|--cpu) CPU_REQUEST="$2"; shift ;;
32+
-c=*|--cpu=*) CPU_REQUEST="${1#*=}" ;;
33+
-m|--memory) MEMORY="$2"; shift ;;
34+
-m=*|--memory=*) MEMORY="${1#*=}" ;;
2935
*) echo "Unknown parameter passed: $1"; usage; exit 1 ;;
3036
esac
3137
shift
3238
done
3339

40+
# Set default threads, cpu, and memory if not provided
41+
THREADS="${THREADS:-10}"
42+
CPU_REQUEST="${CPU_REQUEST:-2}"
43+
MEMORY="${MEMORY:-5}"
44+
45+
# Calculate CPU limit (always 2 more than request)
46+
CPU_LIMIT=$((CPU_REQUEST + 2))
47+
3448
# Validate arguments
3549
if [[ -z "$SOURCE_PVC" || -z "$TARGET_PVC" || -z "$NAMESPACE" ]]; then
3650
echo "Error: Missing required arguments."
@@ -50,14 +64,31 @@ spec:
5064
containers:
5165
- name: rsync-container
5266
image: image-registry.openshift-image-registry.svc:5000/openshift/tools
53-
command: ["/bin/sh", "-c", "time rsync -avh --omit-dir-times --stats --human-readable --info=progress2 --partial --ignore-errors /tmp/source/ /tmp/target/; while true; do sleep 3600; done"]
67+
command:
68+
- /bin/sh
69+
- -c
70+
- |
71+
start_time=\$(date +%s)
72+
find /tmp/source -type f -print0 | xargs -0 -n1 -P${THREADS} -I{} sh -c '
73+
target_dir="/tmp/target/\$(dirname "{}" | sed "s|/tmp/source||")"
74+
mkdir -p "\$target_dir"
75+
rsync -avh --omit-dir-times --stats --human-readable --info=progress2 --partial --ignore-errors "{}" "\$target_dir/"
76+
'
77+
end_time=\$(date +%s)
78+
duration=\$((end_time - start_time))
79+
duration_min=\$((duration / 60))
80+
duration_hr=\$((duration / 3600))
81+
echo "Data migration completed successfully."
82+
echo "Time taken: \${duration} seconds (\${duration_min} minutes, \${duration_hr} hours)."
83+
echo "You can now safely remove the migration pod."
84+
while true; do sleep 3600; done
5485
resources:
5586
requests:
56-
memory: "2Gi"
57-
cpu: "250m"
87+
memory: "${MEMORY}Gi"
88+
cpu: "${CPU_REQUEST}"
5889
limits:
59-
memory: "2Gi"
60-
cpu: '2'
90+
memory: "${MEMORY}Gi"
91+
cpu: '${CPU_LIMIT}'
6192
volumeMounts:
6293
- name: source-pvc
6394
mountPath: /tmp/source

0 commit comments

Comments
 (0)