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
74usage () {
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
3238done
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
3549if [[ -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