All hardware fails eventually, and eventually everyone will have to deal with a catastrophic hardware failure. Whether through failure or the need for migration, system administrators will need at one time or another, to move to new machines or to recover files lost. This is a way, and just a beginning, for sysadmins to work more efficiently.
Choices for recovering an Ubuntu Linux machine are many, and the most popular for this restoration are: image backups, re-installation (and hopefully not having to re-build from scratch).
There can be draw backs to just making image files of an entire operating system. Size, and usability come to mind when talking about storing, what can turn into massive image files. Imagine two or three terabyte files sitting on a drive, with no where other than another hard drive to store them on. This is one place where the problem with system images or drive images lies, in the storage. It is a good idea to tar-up all of the files that change, but what happens on a new system if all of the binary files are not installed? Installing these binaries can take the most time out of the day for a system administrator, and errors can be made.
For most systems that are serving web pages, only a few files are modified that need to be saved.
- The directory that contains the WWW directory, in a typical Ubuntu apache2 install this would be /var/www.
- The database, if one is used for the web site. Export a db from MySQL using:
$ mysqldump –opt database-name > specific-db.sql
( for a specific database ) and
$ mysqldump –opt –all-databases > all-databases-db.sql -or-
mysqldump -u user-id -h host-name –opt –all-databases > all-databases-db.sql
Restoring the database:
$ mysql database < database-dump.sql
–There is more to setting up a mysql database and maintaining it than will be covered in this blog post. —
- Specific configuration files such as:
PHP.ini /etc/php5/apache2/php.ini /usr/share/php5/php.ini-dist
- And any specialty scripts or programs that are built for the system that are not located within the WWW directory. Most administrators will locate configuration files that contain passwords and restrictions for the particular web server outside the www directory, thereby limiting access to the sensitive information.
Store all these config files somewhere safe, be sure to date them properly. External storage is best for this, such as a SSD ( solid state drive) or USB drive.
This is where a simple plan can make the process of recovering or migrating to a new machine simple and quick.
To get a list of all the packages installed on a machine, use the ‘dpkg’ command with the ‘–get-selections’ flag.
$ dpkg –get-selections
$ dpkg –get-selections > installed_software_DATE.log
( Dating backups and install.logs can be advantageous, nothing more annoying than
installingtrying to install software from a year ago. )
This file should now be stored with the configuration files, and other back up materials.
Import the installed file. Importing is as simple as exporting, unless the machine has a different release (ie. Ubuntu 8.04 to Ubuntu 9.04). In the case of migration to different releases of Ubuntu, the administrator will have to edit the log file to reflect the newer packages (this is something where you will have problems, if you are installing a kernel for a specific system, the best advice is to check the log file and remove all kernel packages from the list).
$ sudo dpkg –set-selections < installed_software_DATE.log
Use deselect to install the packages.
$ sudo dselect
Place all of the www files, and the configuration files for the system back in the proper directories. The system is restored or migrated.
Please feel free to add any information that could be useful in the comments!