Cpanel Migration Script

#!/bin/bash
#Script Usage:  sh migration.sh <user> <source_IP>
#by Sileep Kumar M S <sileepkumar@gmail.com>

USER=$1
IP=$2
PORT=22

if [ -z "$USER" ] | [ -z "$IP" ]; then
    echo "Usage: sh migration.sh <user> <source_IP>"
else

/usr/bin/ssh -p $PORT -o StrictHostKeyChecking=no root@$IP "/bin/mkdir /home/MIGRATION"
echo "Packing the account $USER"
/usr/bin/ssh -p $PORT -o StrictHostKeyChecking=no root@$IP "/usr/local/cpanel/bin/pkgacct --skiphomedir $USER /home/MIGRATION"
echo "Downloading the package from $IP"
/bin/rm -f /home/cpmove-$USER.tar.gz 
/usr/bin/scp -P $PORT root@$IP:/home/MIGRATION/cpmove-$USER.tar.gz /home/
echo "Restoring the account $USER"

  if [ -f /home/cpmove-$USER.tar.gz ]; then
  /usr/local/cpanel/bin/restorepkg --force $USER
  else
  echo "/home/cpmove-$USER.tar.gz not found"
  fi

echo "Copying home directory of $USER"
/usr/bin/rsync -avz --progress -e "ssh -p $PORT -o StrictHostKeyChecking=no" root@$IP:/home/$USER /home/
echo "Cleaning the backups"
/bin/rm -f /home/cpmove-$USER.tar.gz
/usr/bin/ssh -p $PORT -o StrictHostKeyChecking=no root@$IP "/bin/rm -f /home/MIGRATION/cpmove-$USER.tar.gz"
echo "Migration has been completed for the account $USER"
fi

Comments

Popular posts from this blog

MySQL table conversion

Add addon-domain, sundomain and parked domains via shell in a Cpanel server