I have a BareOS installation with very little modification to the default config files. There are Full, Incremental, and Differential backups being performed. Most clients appear to be being backed up as expected.
However, one of my clients appears to be repeatedly backing up over 10% of the overall filesystem in every incremental cycle.
How do I find the largest files and folders that are being backed up repeatedly?
BAT does not appear to be very helpful here, since it only lists the size of the file node itself, rather than the entire folder size. I'm effectively looking for a du
command that works within the BareOS framework for a specific backup attempt.
Please note that an important update has been added at the end of the fist part
Unfortunately, even if it's very easy to check exactly what's happened with a particular backup, it's not so easy to get the filesize of backupped files.
Let's get deeper with some examples.
In my case, from
bconsole
I can get the list of last jobs with:From the above, you can see two jobs:
Let's focus on Job 7060, as it's an incremental one. Let's check which files were backedup:
So Job 7060 interested one file (Backup_Plone.bkf) and one directory (the containing folder).
Unfortunately, as you can see, the output of
list files jobid=7060
does NOT present the filesize you need so.....it's useful, hopefully, but does not solve your problem.Let's step ahead.
I've traveled allalong the bareos official documentation being unable to find the proper way to get "filesizes" from within bconsole. So I decided to get the heavy way: direct SQL access to the catalog.
Note: Please, be extremely careful when dealing with direct access to catalog as every single unproper action can lead to serious damage, with related data-loss!
Once connected to the DB-engine (MySQL, in my case.... but this is a detail, as with PostgreSQL it's the same), I saw that backupped file metadata are stored (...among others) in:
File
table: it stores mostly all the metadata, with the exception of...Filename
table: it store the filename of the backupped filePath
table: it store the full-path of the backupped fileWith a big surprise, I discovered that the
File
table does not include asize
field. So it's not possible, with a simple query, to get what we need. Anyway, I found an interestingLStat
field (more on it, later).So I fired up following SQL query:
and got back following results:
As for the
LStat
field, in the Official BareOS Developer Guide I saw:So, now, the problem is:
and, as I would bet for a "YES! Definitely!":
A quick search for "BareOS LStat" lead me to several results. In a few seconds I got this thread, including several comments about the LStat field, including a little PERL script to properly decode it. Here it is (*courtesy of Brian McDonald, 2005 *), slightly modified to better suite your need:
When launched and given an LSTAT string, it reports lots of data, including the filesize (st_size, last field of the output):
So, now, we have the filesize but, unfortunately, it's not easily accessable in a single query to find the biggest file of a single backup job.
Several solutions exists:
if you're running MySQL 5.6.1 or later, or a DBMS engine supporting BASE_64 enconding/decoding, you could query for a SUBSTR of the LSTAT and then asking the DB engine to decode it's value as a Base64 one. For example, see here
you could write a STORED PROCEDURE. Actually it should be already present in PostgreSQL, as for this (who state: "...Added sample postgresql stored procedures for lstat field....");
you could write a little PERL script, querying the catalog and going through the decoding stuff
...
Hope this will be enough ;-)
Update 1
I've just discovered the existence of the BVFS API, explicitely "...intended mostly for developers who wish to develop a new GUI interface to Bareos...".
Those APIs provide a new set of commands (so-called "dot-commands"), including an interesting
.bvfs_lsfiles
which shows on the console some metadata, including the LSTAT field. So:Also, with BareOS 15.2 a new "API mode 2" have been introduced, adding support for JSON output. I've just tested that:
.bvfs_lsfiles
, contains the file-size field, properly decoded.Here follow an example:
So, in the end, with a recent version of BareOS, the original problem seems to be solvable without direct access to the catalog.
While I appreciate @damiano-verzulli 's effort, a discussion in the BareOS IRC channel on FreeNode eluded this response:
It turns out that Kjetil Torgrim Homme has already written a script to do this, called
bacula-du
. (Along with quite a few other useful scripts!)They're all listed and obtainable from here:
http://heim.ifi.uio.no/kjetilho/hacks/
In particular
bacula-du
is explained as this:There's one small note I have to add here. For this to work, it has to have access to the database (obviously). In the default configuration, it uses a user-based security mechanism, so you have to run the command as the bareos user for it to work, e.g.