Exclude Virtual Filesystems in System Backups
When backing up a Linux system, ensure that you are excluding virtual filesystems like /proc, /sys, and /dev. Including them in a backup can cause issues during restoration.
Table of Contents 📖
Virtual Filesystems
A common pitfall during full system backups is accidentally including virtual filesystems like /proc, /sys, and /dev. These directories contain dynamically generated data, not actual files, and including them in a backup can cause issues during restoration. For example, consider the output of /proc/uptime.
cat /proc/uptime
22848618.98 7324.17
cat /proc/uptime
22848622.85 7327.60
The information in this virtual file is dynamic and based on the system's uptime. Virtual filesystems, like /proc, are special directories in Linux that provide an interface to system hardware and kernel information. They do not store persistent data and are generated at runtime.
Wny Exclude Virtual Filesystems
Including virtual filesystems in a backup can cause the following issues:
- Unnecessary space usage
- Restoration issues due to overwritten runtime-generated data
- Security risks due to exposure of device files (such as in /dev)
- Backup failure as some virtual filesystems contain pseudo-files that are infinite in size or have special properties
Avoiding Virtual Filesystems
A common way to backup a system is to use tar or rsync. The following commands will exlude the virtual filesystems from the backup:
sudo tar --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run --exclude=/tmp --exclude=/mnt --exclude=/media --exclude=/lost+found -czvf /path/to/backup/system-backup.tar.gz /
sudo rsync -aAXv --exclude={"/proc","/sys","/dev","/run","/tmp","/mnt","/media","/lost+found"} / /path/to/backup/system-backup.tar.gz
INFO: Many modern systems also have tools like Timeshift to automatically exclude virtual filesystems.