Linux - filtered backups with preview

Currently, I experiment with a possibility to backup the whole filesystem to a single compressed file. During the backup process, I want to conveniently preview the directory structure which will be actually backed up.


I have prepared separate scripts for multiple stages of this process. While doing a backup, I run them in order.

The scripts have hardcoded paths - review and edit the scripts and files below before using them.

Stage 1: Mount a filtered filesystem


mkdir -p /tmp/to_backup
rofs-filtered /tmp/to_backup -o source=/ -o config=/home/user/bin_settings/rofs-filtered.rc

rofs-filtered is available at GitHub or as AUR package for Arch Linux.

The rofs-filtered.rc file contains the filter rules as regular expressions. E.g. the contents of my file are:

^/home/user/VirtualBox VMs$

Stage 2: Check what occupies the most space


filelight /tmp/to_backup

filelight is a GUI application which shows you a graphical representation of the space occupied by the parts of the filesystem tree. Mostly, this application can be obtained from standard Linux distribution repositories.

Stage 3: Check the backup size


tar -czf - /tmp/to_backup | pv > /dev/null

This only tries to create the compressed backup, without storing it anywhere. It is faster than Stage 4 and the result does not occupy any disk space.

If the result of this step shows that the backup is too large, I return to Stage 3 to see the largest directories, and then possibly return to Stage 2 to edit the filesystem filter.

Stage 4: Execute the backup


DATETIME=$(date '+%Y%m%d_%H%M%S')

tar -czf - /tmp/to_backup | pv > "/mnt/backup_server/zip/${DATETIME}_${RANDOM}.tar.gz"

This creates the same backup file as Stage 3 and actually stores it somewhere.

Stage 5: Unmount the filtered filesystem


fusermount -u /tmp/to_backup
Written on July 5, 2023