Results 1 to 4 of 4
-
09-11-2019, 11:54 AM #1New Member
- Join Date
- Jul 2012
- Posts
- 2
Bash script for auto transfer cpanel accounts to directadmin
Hi everyone
I have created a bash script to automatically transfer cpanel user accounts to directadmin, which I will share with you.
Hope it will be useful.
The script executes these steps:
- Creat a full backup of account on cpanel. (This full backup does not include the public_html directory)
- Transfer backup to directadmin server and restore that.
- After the full backup in directadmin restores the user public_html directory information in cpanel transfer to the user public_html directory in directadmin.
- Deletes cpanel full backups from both servers in order to prevent space occupancy.
- Changes the account ip in the cpanel to the directadmin server ip to load the site from the directadmin server.
- Suspends the user in cpanel server so that the user does not have access to the previous panel.
These steps are performed respectively for each cpanel user account.
Note that you need to add the DirectAdmin IP server from the "Add a New IP Address" section on the WHM panel before running the script.
If you do not intend to change the IP after transferring the account, remove the following line from the script:
/usr/local/cpanel/bin/setsiteip -u $USER $DEST
Note that the connection between servers must be established via the ssh key.
Important note that none of cpanel accounts should be suspended! If so, the script will not work correctly.
You can see the script below:
Code:#!/bin/sh #You can get the script updates from https://bit.ly/2ktJVHn #Note that you need to add the DirectAdmin IP server from the "Add a New IP Address" section on the WHM panel before running the script. #If you do not intend to change the IP after transferring the account, remove the following line from the script: #/usr/local/cpanel/bin/setsiteip -u $USER $DEST #Note that the connection between servers must be established via the ssh key. #Important note that none of cpanel accounts should be suspended! If so, the script will not work correctly. DEST="192.168.1.1" #Your DirectAdmin Server IP PORT="22" #Your Directadmin Server ssh Port cd /var/cpanel/users for USER in *; do if [ "$USER" != "system" ] then echo "starting transfer process for $USER" sleep 2 #backup cpanel account (public_html excludes) and transfer to directadmin server. /scripts/pkgacct $USER --skippublichtml rsync -av -e "ssh -p $PORT" /home/cpmove-$USER.tar.gz root@$DEST:/backup/ #Restore backup in directadmin server. ssh -p $PORT root@$DEST " chown admin.admin /backup/ chown admin.admin /backup/cpmove-$USER.tar.gz echo 'action=restore&ip%5Fchoice=select&ip=$DEST&local%5Fpath=%2Fbackup&owner=admin&select%30=cpmove-$USER.tar.gz&type=admin&value=multiple&when=now&where=local' >> /usr/local/directadmin/data/task.queue echo "backup is restoring in DirectAdmin!" sleep 2 while \$(grep -Fq "action=restore" /usr/local/directadmin/data/task.queue 2>/dev/null); do printf "%s""$i" .; sleep 2; done; while \$(test ! -d /home/$USER/public_html); do printf "%s""$i" .; sleep 2; done; printf '\n' echo "backup restoration completed in DirectAdmin!" sleep 2 " #transfer public_html files and dirs to destinaton server rsync -av -e "ssh -p $PORT" /home/$USER/public_html/ root@$DEST:/home/$USER/public_html/ ssh -p $PORT root@$DEST " chown -R $USER.$USER /home/$USER/public_html/ find /home/$USER/public_html/ -type d -exec chmod 755 {} \; " #remove backup files in order to free space ssh -p $PORT root@$DEST "rm /backup/cpmove-$USER.tar.gz" rm /home/cpmove-$USER.tar.gz #change user ip in order to transfer site loding to destination server. /usr/local/cpanel/bin/setsiteip -u $USER $DEST /scripts/suspendacct $USER "User transferred to Direct Admin." echo "transfer process for $USER has been completed!" sleep 2 printf '\n' fi done
-
09-13-2019, 10:55 AM #2Disabled
- Join Date
- Nov 2012
- Posts
- 34
Important note that none of cpanel accounts should be suspended! If so, the script will not work correctly.
-
09-14-2019, 03:05 AM #3New Member
- Join Date
- Jul 2012
- Posts
- 2
Hello
I've updated the script. Now you can transfer all accounts event the suspended accounts.
Code:#!/bin/sh #You can get the script updates from https://bit.ly/2ktJVHn #Note that you need to add the DirectAdmin IP server from the "Add a New IP Address" section on the WHM panel before running the script. #If you do not intend to change the IP after transferring the account, remove the following line from the script: #/usr/local/cpanel/bin/setsiteip -u $USER $DEST #Note that the connection between servers must be established via the ssh key. DEST="192.168.1.1" #Your DirectAdmin Server IP PORT="22" #Your Directadmin Server ssh Port cd /var/cpanel/users for USER in *; do if [ "$USER" != "system" ] then echo "starting transfer process for $USER" sleep 2 #backup cpanel account (public_html excludes) and transfer to directadmin server. /scripts/pkgacct $USER --skippublichtml rsync -av -e "ssh -p $PORT" /home/cpmove-$USER.tar.gz root@$DEST:/backup/ DOMAIN=$(cat /var/cpanel/users/$USER | grep -w DNS | awk -v FS='=' '{print $2}') #Restore backup in directadmin server. ssh -p $PORT root@$DEST " chown admin.admin /backup/ chown admin.admin /backup/cpmove-$USER.tar.gz echo 'action=restore&ip%5Fchoice=select&ip=$DEST&local%5Fpath=%2Fbackup&owner=admin&select%30=cpmove-$USER.tar.gz&type=admin&value=multiple&when=now&where=local' >> /usr/local/directadmin/data/task.queue echo "backup is restoring in DirectAdmin!" sleep 2 while \$(grep -Fq "action=restore" /usr/local/directadmin/data/task.queue 2>/dev/null); do printf "%s""$i" .; sleep 2; done; while \$(test ! -d /home/$USER/domains/$DOMAIN/public_html); do printf "%s""$i" .; sleep 2; done; printf '\n' echo "backup restoration completed in DirectAdmin!" sleep 2 " #transfer public_html files and dirs to destinaton server rsync -av -e "ssh -p $PORT" /home/$USER/public_html/ root@$DEST:/home/$USER/domains/$DOMAIN/public_html/ ssh -p $PORT root@$DEST " chown -R $USER.$USER /home/$USER/domains/$DOMAIN/public_html/ find /home/$USER/domains/$DOMAIN/public_html/ -type d -exec chmod 755 {} \; " #remove backup files in order to free space ssh -p $PORT root@$DEST "rm /backup/cpmove-$USER.tar.gz" rm /home/cpmove-$USER.tar.gz #change user ip in order to transfer site loding to destination server. /usr/local/cpanel/bin/setsiteip -u $USER $DEST service nginx restart /scripts/suspendacct $USER "User transferred to Direct Admin." echo "transfer process for $USER has been completed!" sleep 2 printf '\n' fi done
-
09-14-2019, 04:07 AM #4Disabled
- Join Date
- Nov 2012
- Posts
- 34
I've updated the script. Now you can transfer all accounts event the suspended accounts.
Similar Threads
-
Is it possible to create customized index page for newly created cpanel accounts ?
By roberts118 in forum Dedicated ServerReplies: 6Last Post: 06-21-2009, 12:20 PM -
Looking for someone to move a few cPanel Accounts to DirectAdmin
By magnuson56 in forum Employment / Job OffersReplies: 7Last Post: 04-09-2009, 04:35 AM -
Tool for transfer cpanel account to directadmin
By tph in forum Hosting Software and Control PanelsReplies: 2Last Post: 04-06-2006, 06:28 AM -
Transfer WHM/Cpanel accounts to H-Sphere
By Walter in forum Employment / Job OffersReplies: 1Last Post: 07-27-2005, 12:01 PM -
Looking for someone to transfer cpanel accounts onto new server.
By matrixnet in forum Other Offers & RequestsReplies: 2Last Post: 05-15-2004, 07:45 AM