Which files do I need to backup for backing up a Ubuntu Server?

I want to back up a Linux Ubuntu server. Since I want to make this backup to a running system without fail, most backup tools are out of the question. Furthermore, the data size of a complete image is also very large, so that a backup takes a relatively long time. This also blocks my PC and slows down the performance of the server during operation. Therefore, I only want to back up the relevant files so that in the case of a deserter I can set up the server quickly with the old configuration. Which files do I have to backup so that I can easily restore the system?

codenovae's picture

I think that is not the best idea

First of all, you generally do not need to back up any files. If you reinstall Linux Ubuntu, all files will be recreated. The question is, what has changed on the system. So you have to remember which programs have been installed or which configuration files have been customized. Here it is recommended to keep a meticulous documentation. This requires a bit of understanding about the directory structure of Linux Ubuntu. In addition, one should be aware that in a system recovery usually other versions of individual programs can be found, so that you usually have to make some adjustments before the system is stable again after restoring specific files. A backup of various configuration files makes sense, but you should still think about a complete system backup. A complete system backup during the operation of a server can not be accomplished with any backup software. We recommend the Mondo Rescue program, which is even used by companies such as Siemens or Lockheed-Martin. If you make only changes to a website, a simple backup via Plesk will be suitable alone. Of course, this works well with Webmin or other solutions usually just as uncomplicated.

 

In order to see the individual server files we recommend the program WinSCP (SFTP client and FTP client), with which you can graphically display the files in directory structure. If you log in, you end up in the root directory. If you have not stored anything in the root directory, you do not need to do any backup directly in this directory. There are usually only symbolic links next to the subdirectories. These links will be recreated anyway when reinstalling the operating system. My example system is Linux Ubuntu 14.4.5 LTS. You can already see that in the case of a backup of individual files, the entire system would have to be rebuilt, unless you reinstalled exactly all identical versions of all installed programs. The version and thus the versions of the installed programs are not up-to-date. Version conflicts are preprogrammed. In a hierarchy under the root directory you will usually find the following files (Linux Ubuntu 14.4.5 LTS):

 

  • bin (contains binaries for Linux, which are indispensable for Linux. This file will be recreated when reinstalling the operating system. Backup not required)
  • boot (is created when reinstalling, backup not required)
  • build (created during new installation, backup not required)
  • dev (re-created on reboot, backup not required)
  • etc (here are most of the configuration files, so be sure to back up this file. Backup Required)
  • home (Each user has their own directory here. Backup required)
  • lib (is created when reinstalling, backup not required)
  • lib32 (created during new installation, backup not required)
  • lib64 (created during new installation, backup not required)
  • lost + found (recreated on reboot, backup not required)
  • media (mount point, backup not required)
  • mnt (mount point, backup not required)
  • opt (additional programs that are not under a free license are installed here, for example, Apache Solr, Google Earth, backup depending on the installations required)
  • proc (re-created on reboot, no backup required)
  • root (main directory - contains only symbolic links next to the subdirectories, no backup required)
  • run (recreated on reboot, no backup required)
  • sbin (is created when reinstalling, backup is not required)
  • srv (this folder is usually empty under Ubuntu, backup is not required)
  • sys (re-created on reboot, no backup required)
  • tmp (re-created on reboot, no backup required)
  • usr (system tools, libraries, installed programs, formerly the users were created there as well, so the name comes from backup may be required)
  • var (In this directory are the created domains, if you make a Plesk backup, you do not need to back up this folder again. Backup required)
  • The links /initrd.img, /initrd.img.old, / vmlinuz, /vmlinuz.old and zookeeper.out (for Apache Solr deployment) will be recreated during reboot or reinstallation of the operating system. Backup not required)

 

In addition, extreme care should be taken with WinScp. If you accidentally delete files there, you can not restore them. With WinScp there is no dustbin, as you know it from Windows. In most cases backing up the folders /home and /etc as well as some configuration files in /opt and /usr will be enough. Downloading /opt and /usr takes a very long time. You should also backup the domains via Plesk or similar service. In conclusion, a complete system backup is still the best solution. Here the tool Mondo Rescue does a good job. All the mentioned above is not a problem for experienced server administrators. Newcomers should possibly try the backup methods first on a test server. There you can also test a worst case scenario to see how long it would take in an emergency to get the system back to baseline.

 

Vote the answer: 
5
Average: 5 (1 vote)
Codemaster's picture

There is a more easy way to do it

You can backup and restore all relevant files with an easy tar command. It will tell system only to backup all relevant files and not dynamically changing system files which will be generated on reboot or reinstallation of the os.

sudo tar -cvpzf backup2018.tar.gz --exclude=/home/server/backup2018.tar.gz -- one-file-system /

Here is what it is doing:

  • sudo grants superuser permissions
  • using tar to backup gzip compressed files of all relevant files
  •  c stands for copy
  • v stands for verbose and means that it will list all backup directories on the flow
  • p stands for permissions
  • z stands for compression method gzip
  • f stands for filename
  • backup2018.tar.gz is the name of backup
  • --exclude=/home/server/backup2018.tar.gz means that new created backup file will be excluded from backup
  • -- one-file-system means that only relevant files should be backed up
  • / stands for entire root directory

With this backup you have all relevant files backed up. The dynamically changing system files of Linux Ubuntu will be created fresh on reboot or reinstallation of the os anyway.

With 

ls or ls-l (you will see the backup file stored in the directory you wanted it to be saved)

In case of disaster you only need to reinstall the same os again with the same Plesk or Webmin panel or whatever and then run the following restore command:

sudo tar -xvpzf /home/server/backup2018.tar.gz -C / -- numeric-owner

  • sudo  grants superuser permissions
  • using tar to restore gzip compressed files of all relevant files
  • x stands for extract
  • v stands for verbose listing all extracted and restored files on the flow
  • p stands for permissions
  • z stands for gzip
  • f stands for filename
  • /home/server/backup2018.tar.gz stands for the backup file path
  • -C / stands for copy into root directory
  • -- numeric-owner means that it should use original owner signatures of files and not of the current host

That's it. If you will do it this way you will always have all relevant files backed up nice and easy. I think programs like mondo rescue are very complex and time-consuming to understand in detail. 

 

 

 

Vote the answer: 
5
Average: 5 (1 vote)