Bulk IP changing from DNS after server migration VestaCP
Here I create a Bash script for VestaCP to automatic IP update in all over the domains and accounts by just one command.
After the a lot of research and complete analysis of vestacp forums found that there is no any official solution for the problem created after server migration is to update the IP which is not even change after regenerate DNS, WEB and Email. Here I just create a script which solve my problem when I need to migrate from IP to other in some cases NAT IP also cause that problem.
How to update IP after Server Migration:
Few days ago we are working to migrate our datacenter to the new location where major of our clients are using VestaCP as control panel. VestaCP provide very perfect and amazing feather for the data migration which is just create the backup using v-backup-users and just upload the generated zip on new server and just execute the command v-restore-user and everything is done. But in our case we have more then 500+ accounts on each server which need to be migrate so the new challenge is to restore each account one by one which is too much time taking process so we create a script for that here. Because still there is no any official method available to restore each account. After just successfully restore we found that again there is a new problem that DNS entry on each domain is still point out on old IP which is not change after a lot of effort all official solutions are not working so I just create the script for that problem and think that you may also need this so I’m sharing it here with you for that you need to perform the following steps.
Create a new file in root or download script from github
Add the following code in the file
#!/bin/bash oldIp=$1 newIp=$2 sed -i "s/$oldIp/$newIp/g" /home/*/conf/dns/*.db sed -i "s/$oldIp/$newIp/g" /usr/local/vesta/data/users/*/dns/*.conf /usr/local/vesta/bin/v-restart-dns echo "Everything done :) all DNS has been replaced from $oldIp to $newIp"
Just save the file and execute by the following method
bash changeDNS.sh 18.104.22.168 22.214.171.124
Here the 126.96.36.199 is the old IP and 188.8.131.52 is new IP just replace it with your IP.
VestaCP after migration to the new server old DNS entry now easily replaced with the above method and you can save your time and efforts.