Instead of using Ansible or some other configuration management tool, after many months of being the admin of this ubuntu 16.04 server, I made a lot of changes to the system: changed config files in /etc, installed packages, enabled and disabled apache2 modules, and so on.
Is there an automated way to create a script or something, that when executed on a clean installation of ubuntu 16.04 (but if it works on any linux even better), can recreate a server that is more or less exactly the same as the one I have right now and is working and running?
Edit: Unfortunately this is not a VM I can just clone.
There's not much you can do when it comes to industry standards right now. If you really need scripts to prepare everything for you then I would :
dpkg -l
along with versions of it.etckeeper
on the new serverrsync
all the/etc
directories from the original server to the "clean" one - ensuring that the files from the "clean" one that aren't present in the original one are deleted (a2dismod
simply deletes symlinks in /etc/apache2/modules-enabled directory so it would be another way of doing the same) - there is an option inrsync
to do just that.After that is done you should be presented (thanks to etckeeper) with a git differential of the
/etc/
directory - this can simply(?) be transformed into apatch
script - but it will only work reliably when all package versions will be exactly the same as the original server. This would be however a good base for some real templates foransible
/puppet
/chef
Going down that route you should be able to create some kind of automation to prepare new servers with similiar configuration.
There is another option if "industry standards" do not concern you - just
rsync
/tar
the whole server (you need to stop the databases, or omit them in thersync
to avoid inconsistent file structures ) so you can unpack it over a clean install of ubuntu 16.04 to get exactly the same machine in another location.The only approaches I can think are:
find the list of all installed packages and reinstall them on the target machine; then find all the changed/added configuration files and use tar/rsync/whatever to copy them on the target machine;
if you can't/won't clone by direct RAW copy, you can use tar/rsync (with appropriate parameters) to completely clone the source data to the new machine.
you can use a filesystem dump tool (ie: dump2fs, xfsdump, fsarchiver, etc) to dump the entire filesystem, restoring it on the new machine;
use clonezilla/dd/ddrescue to clone the physical disks (cloning does not need a virtual environment at all) and restore the image on the target machine. This require a livecd-booted source machine or a LVM/BTRFS/ZFS snapshot of the source volume.