68 lines
2.2 KiB
Bash
68 lines
2.2 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Legacy Docker Volumes Sync Script
|
|
# Migrates persistent data from the legacy Swarm cluster to the new GlusterFS storage.
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
# Legacy Cluster Details
|
|
LEGACY_HOST="140.44.4.31"
|
|
LEGACY_USER="dietpi"
|
|
LEGACY_PASS="Katzir476!"
|
|
|
|
# New Cluster Details (Using node .71 as the entry point for GlusterFS)
|
|
NEW_HOST="140.44.4.71"
|
|
NEW_USER="snarf"
|
|
NEW_PASS="Katzir476!"
|
|
|
|
if ! command -v sshpass &> /dev/null; then
|
|
echo "ERROR: 'sshpass' is required. Please install it locally first."
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== Preparing Destination Directory and Askpass ==="
|
|
sshpass -p "$NEW_PASS" ssh -o StrictHostKeyChecking=no "$NEW_USER@$NEW_HOST" "
|
|
echo '$NEW_PASS' | sudo -S mkdir -p /mnt/swarm_shared/legacy_volumes
|
|
echo '#!/bin/bash' > /tmp/askpass.sh
|
|
echo 'echo \"$NEW_PASS\"' >> /tmp/askpass.sh
|
|
chmod +x /tmp/askpass.sh
|
|
"
|
|
|
|
echo "=== Initiating Remote-to-Remote Rsync ==="
|
|
echo "Connecting to Legacy Cluster to start the transfer..."
|
|
|
|
# We execute a block of commands on the legacy server to perform the sync.
|
|
# By using --rsync-path="... sudo rsync", we ensure file UIDs and GIDs are perfectly preserved.
|
|
sshpass -p "$LEGACY_PASS" ssh -o StrictHostKeyChecking=no "$LEGACY_USER@$LEGACY_HOST" "
|
|
cat << 'EOF' > /tmp/run_rsync.sh
|
|
#!/bin/bash
|
|
N_PASS=\"\$1\"
|
|
N_USER=\"\$2\"
|
|
N_HOST=\"\$3\"
|
|
|
|
echo '-> Installing rsync and sshpass on the Legacy Cluster...'
|
|
apt-get update -y > /dev/null
|
|
apt-get install -y rsync sshpass openssh-client > /dev/null
|
|
|
|
echo '-> Configuring Docker data directory on Legacy Cluster...'
|
|
VOLUMES_DIR=\"/mnt/docker/\"
|
|
echo \"-> Source Volumes directory manually set to: \${VOLUMES_DIR}\"
|
|
|
|
echo '-> Starting Rsync Transfer (This may take a while depending on data size)...'
|
|
sshpass -p \"\$N_PASS\" rsync -avzh --progress \\
|
|
--rsync-path=\"SUDO_ASKPASS=/tmp/askpass.sh sudo -A rsync\" \\
|
|
-e \"ssh -o StrictHostKeyChecking=no\" \\
|
|
\"\${VOLUMES_DIR}\" \"\${N_USER}@\${N_HOST}:/mnt/swarm_shared/legacy_volumes/\"
|
|
EOF
|
|
|
|
chmod +x /tmp/run_rsync.sh
|
|
echo \"$LEGACY_PASS\" | sudo -S /tmp/run_rsync.sh \"$NEW_PASS\" \"$NEW_USER\" \"$NEW_HOST\"
|
|
rm /tmp/run_rsync.sh
|
|
"
|
|
|
|
echo "=== Cleaning up ==="
|
|
sshpass -p "$NEW_PASS" ssh -o StrictHostKeyChecking=no "$NEW_USER@$NEW_HOST" "rm -f /tmp/askpass.sh"
|
|
|
|
echo "=== Volume Sync Complete! ==="
|