Linux - What directories should I exclude when backing up a server?

Better Stack Team
Updated on November 23, 2023

When backing up a Linux server, it's important to be selective about which directories you include in your backup and which directories you exclude. The choice of directories to exclude depends on the specific needs and configuration of your server, but here are some common directories that are often excluded from backups:

  1. /proc - This directory contains information about running processes and is a virtual file system. It does not contain real files and should be excluded from backups.
  2. /sys - Similar to /proc, the /sys directory is a virtual file system that contains information about kernel and device parameters. It does not need to be backed up.
  3. /tmp - The /tmp directory typically contains temporary files and can be excluded from backups. It's common practice to configure the /tmp directory to be cleared on system boot.
  4. /var/tmp - This directory may also contain temporary files and can often be excluded from backups.
  5. /var/cache - The /var/cache directory can store cache data, which can usually be regenerated if necessary, so it may be excluded to save backup space.
  6. /var/log - While logs are important for system monitoring and debugging, they can grow quite large. Depending on your needs, you may choose to exclude some log files or directories within /var/log.
  7. /dev - This directory contains device files, which are recreated at boot. It's not necessary to back up device files.
  8. /mnt - This directory is often used for temporarily mounting external devices or network shares. It may not contain critical data and can be excluded.
  9. /media - Similar to /mnt, the /media directory is used for mounting removable media and may not contain critical data.
  10. /lost+found - This directory is used by the filesystem check utility (fsck) and typically doesn't contain user data. It doesn't need to be backed up.
  11. Any other directories or files that are specific to your server's configuration and can be regenerated or reinstalled if necessary.

Conversely, you should include directories containing your important data, configuration files, user data, and application data in your backups. Common directories to include might be:

  • /etc - Contains system-wide configuration files.
  • /home - Contains user home directories.
  • /var/www or other web server data directories.
  • Databases and their data directories (e.g., MySQL, PostgreSQL, etc.).
  • Configuration files for applications and services you rely on.

Always consider the specific needs and requirements of your server and applications when deciding which directories to include or exclude from your backups. Additionally, you should maintain a backup policy that includes regular testing and validation of your backup and restoration processes to ensure your data can be recovered in case of a disaster.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github