Skip to content

Commit 85e07cd

Browse files
committed
add new params and rework migration comand by adding threads
1 parent 798fc57 commit 85e07cd

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

scripts/migrate_pvc_data.sh

Lines changed: 35 additions & 6 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,8 @@ 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: 5)\n"
14+
printf "\t-c|--cpu\t\tNumber of CPU cores to request (default: 1)\n"
1615
}
1716

1817
# Parse arguments
@@ -26,11 +25,24 @@ while [[ "$#" -gt 0 ]]; do
2625
-t=*|--target-pvc=*) TARGET_PVC="${1#*=}" ;;
2726
-n|--namespace) NAMESPACE="$2"; shift ;;
2827
-n=*|--namespace=*) NAMESPACE="${1#*=}" ;;
28+
-p|--threads) THREADS="$2"; shift ;;
29+
-p=*|--threads=*) THREADS="${1#*=}" ;;
30+
-c|--cpu) CPU_REQUEST="$2"; shift ;;
31+
-c=*|--cpu=*) CPU_REQUEST="${1#*=}" ;;
32+
--cpu) CPU_REQUEST="$2"; shift ;;
33+
--cpu=*) CPU_REQUEST="${1#*=}" ;;
2934
*) echo "Unknown parameter passed: $1"; usage; exit 1 ;;
3035
esac
3136
shift
3237
done
3338

39+
# Set default threads and cpu if not provided
40+
THREADS="${THREADS:-5}"
41+
CPU_REQUEST="${CPU_REQUEST:-1}"
42+
43+
# Calculate CPU limit (always 2 more than request)
44+
CPU_LIMIT=$((CPU_REQUEST + 2))
45+
3446
# Validate arguments
3547
if [[ -z "$SOURCE_PVC" || -z "$TARGET_PVC" || -z "$NAMESPACE" ]]; then
3648
echo "Error: Missing required arguments."
@@ -50,14 +62,31 @@ spec:
5062
containers:
5163
- name: rsync-container
5264
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"]
65+
command:
66+
- /bin/sh
67+
- -c
68+
- |
69+
start_time=\$(date +%s)
70+
find /tmp/source -type f -print0 | xargs -0 -n1 -P${THREADS} -I{} sh -c '
71+
target_dir="/tmp/target/\$(dirname "{}" | sed "s|/tmp/source||")"
72+
mkdir -p "\$target_dir"
73+
rsync -avh --omit-dir-times --stats --human-readable --info=progress2 --partial --ignore-errors "{}" "\$target_dir/"
74+
'
75+
end_time=\$(date +%s)
76+
duration=\$((end_time - start_time))
77+
duration_min=\$((duration / 60))
78+
duration_hr=\$((duration / 3600))
79+
echo "Data migration completed successfully."
80+
echo "Time taken: \${duration} seconds (\${duration_min} minutes, \${duration_hr} hours)."
81+
echo "You can now safely remove the migration pod."
82+
while true; do sleep 3600; done
5483
resources:
5584
requests:
5685
memory: "2Gi"
57-
cpu: "250m"
86+
cpu: "${CPU_REQUEST}"
5887
limits:
5988
memory: "2Gi"
60-
cpu: '2'
89+
cpu: '${CPU_LIMIT}'
6190
volumeMounts:
6291
- name: source-pvc
6392
mountPath: /tmp/source

0 commit comments

Comments
 (0)