Dealing with IP address changes when restore from backup or snapshot

Posted February 11, 2014 5.8k views
I would like to create a 'production' environment that hosts a few of my websites. This would involve creating a droplet and configuring apache/nginx, bind/dns, mysql, exim/dovecot, vsftpd, etc. I would then take a snapshot/backup of the droplet to use as a failover. Since there is no guarantee you will get the same IP address when scaling or creating a new droplet from a previous snapshot, I wanted to know the best method to deal with the IP change. Would something simple like find/replace using grep or another utility from the command line work, or would it require a more complex solution?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers
Hi there. You could try this combo of find and sed to find/replace:

find . -type f -name '*.ext' -exec sed -i 's|||g' {} \;

Where is your old IP and is your new one; and -name '*.ext' is file extension (probly best to use *.* if you want to change everything, including logs---might take a while)...

Good luck!
@nooblag Thank you for that example, I think that has me started in the right direction. I would use *.* and exclude multiple directories to speed things up.

With not being able to secure IP address for our droplets, surely this has been dealt with before. Everyone, please do share how you would deal with changing all occurrences of an old IP to the new one in a droplet after you've already setup and configured everything.