1linweb
By:
1linweb

Dealing with IP address changes when restore from backup or snapshot

February 11, 2014 3.5k 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?
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|0.0.0.0|123.123.123.123|g' {} \;

Where 0.0.0.0 is your old IP and 123.123.123.123 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.
Have another answer? Share your knowledge.