work-work.work-logo: A man with brains and a shovel

work-work.work

A blog about goals and obstacles, motivation and procrastination, life's random events and getting things done.

btrfs and a bloated mlocate.db

My previously decribed btrfs/btrbk snapshots-setup runs pretty well so far. But it needs some tweaking.

Taking a look at the most common large files that changed between my backup snapshots, I stumbled upon a stunningly huge mlocate.db file of 2.5 GB.

This file is in each snapshot and eats up precious disk space without adding any value since mlocate is nothing but a list of file names.

Finding the large file

btrbk diff is a very useful command:

$ btrbk diff /mnt/btrfs_ssd/_btrbk_snap/@.20190204T0050 /mnt/btrfs_ssd/_btrbk_snap/@.20190203T0050

--------------------------------------------------------------------------------
Subvolume Diff (btrbk command line client, version 0.27.1)

    Date:   Thu Feb  7 03:00:07 2019

Showing changed files for subvolume:
  /mnt/btrfs_ssd/_btrbk_snap/@.20190204T0050  (gen=195463)

Starting at creation generation of subvolume:
  /mnt/btrfs_ssd/_btrbk_snap/@.20190203T0050  (cgen=192333)

This will show all files modified within generation range: [192335..195463]
Newest file generation (transid marker) was: 195463

Legend:
    +..     file accessed at offset 0 (at least once)
    .c.     flags COMPRESS or COMPRESS|INLINE set (at least once)
    ..i     flags INLINE or COMPRESS|INLINE set (at least once)
    <count> file was modified in <count> generations
    <size>  file was modified for a total of <size> bytes
--------------------------------------------------------------------------------
+ci     1         381  etc/cups/subscriptions.conf
+.i     1          91  etc/cups/subscriptions.conf.O

(I spare you the file list. Here comes the important line)

+c.     2  2498879488  var/lib/mlocate/mlocate.db

This is whooping 2.5 GB if file names in this database.

The reason

Mlocate is indexing every single file name in every single one of my snapshots. Over the years this can become extremely large.

The solution

Edit this line in the file /etc/updatedb.conf

PRUNEPATHS="/tmp /var/spool /media /var/lib/os-prober /var/lib/ceph /home/.ecryptfs /var/lib/schroot"

and add /mnt to it. That's where I have all my snapshots mounted.

After running

$ updatedb
$ ls -lh /var/lib/mlocate/mlocate.db
-rw-r----- 1 root mlocate 4,9M Feb  7 02:54 mlocate.db

The file is only 4.9 MB, which is only 0.2% of the huge file that I had before.