Borg-Backup Archive Storage Stats
Borg (Borg Backup) is a FOSS project that provides a space efficient (via dedpulication, and compression) and secure backup solution. The best part is that it is scriptable, and you can run an hourly cron to make sure that you have hourly backups of your data.
One thing that the current version was missing, is a way to easily view how much space each Archive takes within a particular repository. It does provide two commands that can be combine in a simple bash script to give us the needed results.
borg list gives us a list of Archives within a repository.
The following:
borg list /path/to/repo
Will give us this output:
...
Laptop-2017-11-18-1400 Sat, 2017-11-18 14:00:01
Laptop-2017-11-18-1500 Sat, 2017-11-18 15:00:02
Laptop-2017-11-18-1600 Sat, 2017-11-18 16:00:02
Laptop-2017-11-18-1700 Sat, 2017-11-18 17:00:01
Laptop-2017-11-18-1800 Sat, 2017-11-18 18:00:02
...
It is basically a list of all the archives, with their name and the date/time of their creation.
But we only need name, which be easily acheaved by adding the –short argument as such:
borg list --short /path/to/repo
So now we have the following:
...
Laptop-2017-11-18-1400
Laptop-2017-11-18-1500
Laptop-2017-11-18-1600
Laptop-2017-11-18-1700
Laptop-2017-11-18-1800
...
Each of the above lines we can feed to the borg info command as following:
borg info /path/to/repo::Laptop-2017-11-18-1400
Wich will give us an output as such:
Name: Laptop-2017-11-18-1400
Fingerprint: [Redacted]
Hostname: [Redacted]
Username: max
Time (start): Sat, 2017-11-18 14:00:01
Time (end): Sat, 2017-11-18 14:00:34
Command line: /usr/bin/borg create --stats -v --compress zlib,6 [Redacted]
Number of files: 182284
Original size Compressed size Deduplicated size
This archive: 15.78 GB 10.15 GB 12.80 MB
All archives: 1.91 TB 1.28 TB 41.11 GB
Unique chunks Total chunks
Chunk index: 631558 29090226
From the above we are only interested in the line showing us the name of the archive, and the actual line showing us the space used by said archive. So I just use grep “Name:|This” to filter out the unneeded lines, as such:
borg info /path/to/repo::Laptop-2017-11-18-1400 | grep "Name:\|This"
Name: Laptop-2017-11-18-1400
This archive: 15.78 GB 10.15 GB 12.80 MB
So we now can use these two simple commands (with some bash glue) to have the following little script GetBackupDetails.sh:
#/bin/bash
borg list --short $1 | while read line; do borg info $1::$line | grep "Name:\|This" ; done
We can save it to a folder that is defined within the current user’s or system’s path, and we will be able to call it from any directory as such:
GetBackupDetails.sh /path/to/repo
It uses borg list –short to generate the list of archives, which are then passed line by line (1 archive per line) to borg info, and cleaned up using grep. Giving us the following result:
....
Name: Laptop-2017-11-18-1100
This archive: 15.79 GB 10.16 GB 28.48 MB
Name: Laptop-2017-11-18-1200
This archive: 15.78 GB 10.15 GB 20.38 MB
Name: Laptop-2017-11-18-1300
This archive: 15.78 GB 10.15 GB 13.47 MB
Name: Laptop-2017-11-18-1400
This archive: 15.78 GB 10.15 GB 12.80 MB
Name: Laptop-2017-11-18-1500
This archive: 15.78 GB 10.15 GB 23.78 MB
....
The above can be outputed to the terminal, or preferably to a file or to less for easier viewing.
GetBackupDetails.sh /path/to/repo | less