IP swap scripts with a timed automatic rollback
Two Bash scripts that move a server's IP to its replacement and put everything back by themselves unless someone confirms the change.
In plain terms
Every server on a network has an IP address, the number other machines use to reach it. Some of our clients' systems send their logs to a fixed IP, so when an old log collector is replaced, the new machine has to take over the old one's address.
That swap is done over SSH, a remote connection to the server, and the connection runs over the very address being changed. If the new address doesn't come up properly, you're locked out of a machine in someone else's building, with no way to undo it from your desk.
So the change needed a way back that doesn't depend on still being connected.
The problem
Swapping IP addresses between an old and a new log collector meant editing network configuration over the connection that the edit could cut. A mistake could leave a client's collector unreachable and its logs with nowhere to go.
What I did
I wrote two Bash scripts, one for Ubuntu servers that use Netplan and one for Debian servers that use the interfaces file. Each lists the machine's addresses, asks which one to replace, backs up the network configuration, applies the new IP and restores the backup straight away if the network won't come back up.
Before it applies anything, each script starts a timer in the background. Run on both servers at the same moment, they swap addresses together; if I can reconnect on the new addresses, one command cancels the timers and the swap stays. If I can't, the timers run out and both servers put their original configuration back on their own.
The outcome
Written for the log collector migration (the previous case study), where they moved a financial asset manager's fixed-IP log collectors to new machines across three offices without reconfiguring a single log source. The scripts are open source on GitHub.