Linux which directory to backup

What directories do I need to back up?

What are the directories one should back up, in order to have a backup of all user-generated files? From a vanilla debian install, I can do enough apt to get the packages that I want. So if I don’t want to backup the entire system, where all in the filesystem do user-generated configuration and data files reside?

Missing in all of these answers is what happens after you back the files up. Do you just copy them back once the new install completes? What problems could arise when you do that?

I think I’m just identifying a flaw that even Linux has. Hopefully maybe it will affect future design of the OS.

+1 for not using «backup» as a verb. I get tired of seeing otherwise intelligent people use it that way.

7 Answers 7

As this question has many different answers, the following list should combine the suggestions into one comprehensive list:

Under most circumstances you want to backup these:

  • /home/ for user data and configuration.
  • /etc/ for system wide configuration files.
  • /var/ contains a mix of directories you usually want to backup and those you don’t want to backup. See below for a more detailed explanation.

Some more directories to consider are:

  • /usr/local/ hand-installed packages (i.e. not installed through apt) are installed here. If you have packages installed here, you may want to backup the whole directory, so you don’t have to reinstall them. If the packages themselves aren’t important to you, it should be enough to backup /usr/local/etc/ and /usr/local/src/ .
  • /opt/ if you didn’t store anything here, you don’t need to back it up. If you stored something here, you are in the best position to decide, if you want to back it up.
  • /srv/ much like /opt/ , but is by convention more likely to contain data you actually want to backup.
  • /root/ stores configuration for the root user. If that is important to you, you should back it up.

/var/

/var/ contains many files you want to backup under most circumstances, but also some you don’t want to backup.

You probably want to backup these:

  • /var/lib/ this directory contains variable state data for installed applications. Depending on the application you want to backup that state or you don’t. If you want to be on the safe side, you can just back up everything. Otherwise you can look at each sub-directory and decide for yourself if the data contained is important enough to you to back it up.
  • /var/mail/ you normally want to backup local mails.
  • /var/www/ if your web root is located here and this is the only place where your web content is stored, you want to back it up.
  • /var/games/ you may want to backup these, if system wide game data is important enough for you (not many games use this storage though).
  • /var/backups/ usually contains files that are automatically generated from other data that you usually want on a backup, but that would take an unnecessary amount of space in the backup or is otherwise cumbersome to backup. For example dpkg dumps a list of installed packages here, so you can later know which packages to install after restoring the backup. You probably want to backup this.
  • /var/spool/cron/crontabs/ might contain many commands or a complex schedule, even with dependencies on other systems, that has taken considerable effort to put together.
Читайте также:  Vlc linux log file

You probably don’t want to backup these:

  • /var/cache/ contrary to the name, some contents of this directory are important, so check each subdirectory individually, as a rule of thumb, everything you put here yourself is important. You also might want to backup /var/cache/debconf/ .
  • /var/lock/ locks usually (always) don’t need to be backed up.
  • /var/run/ contains data that is only important for your running system, i.e. when you shutdown you system, it will not be needed any more.
  • /var/spool/ (other than /var/spool/cron/crontabs , see above) normally important data shouldn’t be stored here, but you might want to check.

You have to decide yourself on these:

  • /var/local/ you normally know if you stored something here and whether you want it on a backup or not.
  • /var/opt/ see /var/local/ or better check if something important is stored here.
  • /var/log/ depends on whether your logs are important to you and if you have enough space to store them (they might take a lot of backup space over time).

Источник

9 Linux directories you must back up and one you shouldn’t

9 directories you must back up and one you shouldn't

Backups are a standard sysadmin service. In other words, everyone in an organization, from the CEO to the temporary worker, depends on us to provide backups. People make mistakes, and you’re going to need backups of user data, corporate data, and logs. But it’s not obvious on Linux systems exactly what you need to include in a backup set. This article guides you as to what you should and should not include in your backups.

Backups are not romantic or exciting, but they’re necessary. If you want to know how important backups are to any organization, you need to experience a failure or an outage without a good backup. There’s no recovery without a good backup. Sometimes I think that backups are an afterthought because of the many, many times I’ve seen them neglected, ignored, and failed.

  • Backup — A set of directories and files archived to tape, disk, or cloud.
  • Back up — The process of creating a backup.

One of the first questions that new system administrators ask is, What should I back up? The answer is pretty easy: Everything you need to and nothing that you don’t. Yes, it’s a bit sarcastic, but it’s 100 percent true. The following is a list of directories that you must regularly back up and one that you should never back up. These directories are in no particular order.

/etc

Automation advice

The /etc directory contains a system’s configuration files. It includes the user file, the group file, the password file, networking information, most application configurations, startup files, filesystem information, mount points, and other system-wide configuration files. Without this directory, it will take you a very long time to put the system back to where it was before the outage or failure. Without a good backup of /etc, you will likely have to reinstall your system from media, reinstall all of your applications, and basically start fresh as you would with a new system.

Читайте также:  Canon lbp 3010b astra linux

/home

All user data, downloads, documents, pictures, and miscellaneous files are kept in the /home directory under the user’s name. For example, my home directory is /home/khess. For a user, there’s no more important directory to back up on a system. Users assume that you’ll include their personal files in your daily backups. You should do so. Trust my experience on this one. It’s been said that good judgment comes from experience, and experience comes from poor judgment. This is true, and I have stories to prove it.

/root

The root user’s home directory is an important one to include in a backup. This directory is where you, the system administrator, keep downloads, configurations, scripts, notes, and other essential information that is often unique and irreplaceable.

/var

The /var directory holds databases, web pages, crontabs, log files, and DNS zone files. Files in the /var (variable) directory change and grow on a daily basis. Because of the data it holds, the /var directory will often have its own mount point on its own filesystem and its own disk or disk array.

/usr/local/bin

The /usr/local/bin directory can be empty, or it can contain root-owned scripts or application executables that aren’t part of the standard system executables list located in /usr/bin or /usr/sbin. If the directory is empty, I always create a /usr/local/bin/empty file to let me know that it has no files in it rather than thinking that my backup missed an entire directory’s files. Yes, I’m OCD. Don’t judge me.

/usr/local/sbin

The /usr/local/sbin directory is important for the same reasons as /usr/local/bin. It too is often empty, and I also place a /usr/local/sbin/empty file in it to let me know its status.

/srv

The /srv directory is somewhat of an anomaly. It’s used optionally for internet-related services files such as WWW uploads, FTP files, CVS, and so on. I always back it up, but I also place my standard /srv/empty file in it because it may be empty for the entire life of the system. Some sysadmins use it as a file upload/download directory for the aforementioned services, but its use is random and somewhat rare.

/opt

The /opt directory is often used for third-party software or software that a sysadmin wants to keep separate from standard directories. I always install document management systems, Webmin, and other applications to it that I don’t want occupying locations such as /usr/local. That’s just a personal preference and you not required to do so. I find /opt is a good location to install software that I want to test, such as a new document management system or other application. If it’s empty, I create my /opt/empty file there.

Shared directories

A shared directory might belong to a particular group, such as finance or human resources, that has special permissions. You definitely want to back up /finance, /data, or /hr if your system has such directories. Don’t create these types of directories until you have a need. Shared directories are important to include in a backup because users store corporate data in them, and there may be no other copies.

NFS-mounted directories

NFS-mounted directories should generally be excluded from your backup scheme. Why? Because these directories are mounted from remote systems. They can be in the same data center, or they could be from a system very far away. Over-the-network backups can be fine if you have a very fast network or a small volume of files. It’s my recommendation that you do not back up over the network unless it’s necessary. Back up this data from the local system that houses it. You don’t want a network glitch to corrupt your backups and render your data useless.

Читайте также:  Linux все виды таблица

Wrap up

The two purposes of a backup are to ensure that you have good copies of your data and that it can be restored. Going through the motions of making backups is a waste of resources if the backups aren’t usable. I’ve been there. This is why you must check your backups periodically by restoring a file.

Backups are always important. Do them. Check them. Don’t trust that they’re being done by someone else.

Источник

Which are the most important directories to backup on a Linux server?

I’m running an Ubuntu 9.10 Linux server. I’m trying to find a way to backup the machine while it is running and from what I see, this eliminates the disk clone utilities. All of the disk clone stuff I have seen for Linux requires that you reboot into a special live CD. So my question is this, what is the best solution for backing up the system while it is running? Also, I don’t really care about the OS config too much, I just want to be able to keep my stored files and my programs that I have installed on it. Thanks

3 Answers 3

The important directories are /etc , /home , /var , and /srv . You may want to add /root , and remove unneeded bits from /var .

rsync is good if you want the files to be directly accessible, tar is fine if you don’t.

Ok thanks for that info. Are there any disk clone backups that support «live» backups? Backups that don’t require me to shutdown or deal physically with the server (such as put a CD in).

@Ashesh: In the end it’s up to the person performing the backup to determine which files are truly important to them.

I agree with Ignacio Vazquez-Abrams about /etc/ /home/ and some parts in /var/.

But don’t forget to save a list of the installed packages, so you know what programs was installed.

dpkg --get-selections > dpkg.list 

I’m using backup2l to backup my Debian server (AFAIK Ubuntu is a derivative of Debian). If configured correctly it automates your backup, e.g. getting the dpkg selections, creating differential and incremental backups (depending on your settings) and storing it in an archive. A post backup hook triggers rsync which syncs my archive with a remote copy.

I’m backing up /etc /var (with some exclusions like caches), /root , /home . Just think about what you have changed in addition to that and add it to the list. I for instance dump my sql databases in a special directory and save it, too.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Оцените статью
Adblock
detector