Results 1 to 4 of 4
  1. #1

    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

  2. #2
    Important note that none of cpanel accounts should be suspended! If so, the script will not work correctly.
    Does it mean account that are suspended will not be transferred or not to be backed up??

  3. #3
    Quote Originally Posted by ikiManaged View Post
    Does it mean account that are suspended will not be transferred or not to be backed up??
    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

  4. #4
    I've updated the script. Now you can transfer all accounts event the suspended accounts.
    Thank you for your contribution which is very helpful and saves time cp to DA migration. I have an idea, for a server that has many resellers, all reseller account should be restored first.

Similar Threads

  1. Replies: 6
    Last Post: 06-21-2009, 12:20 PM
  2. Looking for someone to move a few cPanel Accounts to DirectAdmin
    By magnuson56 in forum Employment / Job Offers
    Replies: 7
    Last Post: 04-09-2009, 04:35 AM
  3. Tool for transfer cpanel account to directadmin
    By tph in forum Hosting Software and Control Panels
    Replies: 2
    Last Post: 04-06-2006, 06:28 AM
  4. Transfer WHM/Cpanel accounts to H-Sphere
    By Walter in forum Employment / Job Offers
    Replies: 1
    Last Post: 07-27-2005, 12:01 PM
  5. Looking for someone to transfer cpanel accounts onto new server.
    By matrixnet in forum Other Offers & Requests
    Replies: 2
    Last Post: 05-15-2004, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •