Upgrading Debian GNU/Linux can be a tedious task if you have several servers that need to be upgraded. I had many servers that required an OS upgrade and I couldn't find a tool to ease the upgrade.
I know that automating the upgrade is very complex as it depends on the status of the server packages. Things like using third party repositories or manually installed packages will most likely cause troubles during an Debian version upgrade. However, I decided to code an script to help me upgrade servers that met the following requirements:
Upgrade using tmux: It is critical that the upgrade keeps running even if ou lose network connectivity. Not only that, but being able to keep track of the upgrade or interact after a connection loss is mandatory. tmux allows to run the upgrade in the background and attach to the upgrade at any time.
Hook support: Being able to execute commands both before and after the upgrade adds an incredibly versatility. This was a must-have feature.
Hability to be non-interactive: Although risky, being able to run an upgrade on its own comes fairly handy in many scenarios.
The script I coded is called simply debian_upgrade.sh and this is how it looks.
The script is available in my github tools repository.
I've already upgraded many servers with it and it worked surprisingly well im the vast majority of my installations, having most of them upgraded in a matter of 30 minutes.
As an example of how I upgraded my LEMP servers, this is the command that I used in all of them: ./debian_upgrade.sh -p 'env DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=mail apt-get purge -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" php* && pip uninstall -y docker docker-py docker-pycreds ; sed -i "s/^innodb_additional_mem_pool_size.*//g" /etc/mysql/my.cnf && systemctl restart mysql'
Here I apply some needed modifications to clean things up before the upgrade. After the upgrade finishes I just need to run my Ansible playbook to install all missing packages and configurations.
I hope you find this tool useful. Please feel free to send some feed back via github or just contact me.