Advice on backing up 14 million small files
Hi All,
So excuse the brain dump, im not really sure how to phrase this...
We recently replaced an older backup system relying on Duplicity with Borg + Borgmatic as all our testing showed that the transfers are faster, the compression is handled better and the deduplication is AMAZING in our environment. The first run completed in about... a week (close to 2TB of data pushed over a international upload link) and all the checks and verifications came back clean.
Now, we are trying to get the backups to do their usual daily incremental thing, but its just not working quite the way it should - biggest issue is that the backup runs are taking more than 24hrs to complete, meaning they are no longer "daily" backups.
Based on some probing and a few strace -p's, it seems like most of the backup time is spent on writing to the .cache/ files and not actually transferring the data. This suggests to me that the system is having a hard time indexing and chunking the 14 million small files that make up the backup (text, images, database dumps, PDF's etc). During this time, Borg sits at around 13.5G RAM used, and the system is swapping almost 3G. Drive IO loads are averaging at around 25 - 30% across the board.
Backup is triggered via borgmatic, so no chunking params have been changed.
System specs: OS: Debian Jessie (3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux ) 4-core Xeon E3 16GB ECC ram Storage is a 10-drive ZFS RAID-10 with zvol's for the backup data, the borg .cache/ stuff and the system swap. arc_max limited to 2G, compression enabled, no dedup, no SLOG, no L2ARC
Borg versions on both ends: borg 1.0.8
Based on my math using the RAM consumption formula in the docs page, the borg indexing SHOULD be using around 4 - 5G for my files, but its clearly not. If im understanding the mechanics correctly, this means that the borg ram consumption is causing the system to swap the chunking data, causing the disks to bottleneck the indexing of changes and therefore slowing the entire process down.
Am I missing something here? Does anyone have a suggestion for speeding this process up?
at first glance it seems borg is updating its indexes before doing an actual update
you might want to run with --debug to verify that
By default the checkpoint interval is quite low (5 minutes); try increasing it (--checkpoint-interval).
1.1 has some stuff that - on desktop hardware with magnetic drives - made backing up small files considerably (5-50x) faster (mainly ino-order traversal).
Once the initial backup is done and subsequent backups only mean backing up relatively few changed/new files, borg should be very fast skipping all the unchanged ones and only needs to read/chunk/hash the changed/new ones.
In 1.0.8 this should work ok except for these cases:
- https://github.com/borgbackup/borg/pull/1864 (will be in 1.0.9 - if that affects you, you can workaround by always having at least 1 changed/new file)
- you have many different backup sets, then you might need to increase BORG_FILES_CACHE_TTL - only do that, if that is the case, the files cache will grow even bigger with that (see docs/FAQ).
- unstable inode numbers (see --ignore-inodes) - should not be the case for zfs
It's bad for performance that your system is running out of (real) RAM and starts to swap. Using the formula and considering that in your case you have at least 14M chunks (because 14M files), I get about 5.6GB of RAM used for the hashtable entries. As a hashtable is avoided to be full, the real RAM allocation can be significantly higher (depending on max/min load factor when hashtable gets resized) and also have peaks when 2 hashtables are temporarily used while a hashtable resize is performed.
The big memory hog in your case is likely the "files cache", due to the 14M files. The chunks index and repo index need much less memory.
things you can try:
- tune BORG_FILES_CACHE_TTL (not too high, not too low)
- partition your backup into multiple repos, so the files count is significantly lower.
- add more RAM
- switch off the files cache. this usually has a big negative performance impact as it won't quickly skip unchanged files any more. but in your case, it will avoid running out of real RAM and paging, so not sure what's better here.
Thanks for the feedback folks. Some feedback from testing now:
1.) It is the files cache consuming my RAM. I ran the borg init --debug ... now and watched the ram crawl slowly up while the output sat on "Reading files cache ..."
2.) Dropping the backup set size does not change things. I did some bash magic to reduce the number of files to send along with the backup, and the same as above happened
(on a sidenote... is it possible to have borg back up symlinks as directories? as in follow symlinks, not back them up as symlinks?)
3.) I am starting a --no-files-cache run now. This seems like a good solution until I can squeeze some more ram into the server. It also sounds fair for my setup, as by my logic, ZFS makes file check operations cheap.
I will also go read up some more about the BORG_FILES_CACHE_TTL now
once you have backed up 14M files / chunks into a repo, they will be in the repo (and caches / indexes) until they get "unused" or expire (files cache ttl). what i meant with partitioning is making new repos for subsets of your data.
So what your saying is instead of running borg create ... /1 /2 /3 .../n, rather run borg create ... /1, borg create ... /2, borg create ... /3, borg create ... /n ?
I was hoping to avoid that so that I could get the benefit of deduplication across all the sets...
# borg init repo1, repo2, ...
borg create repo1::subset1_datetime /subset1
borg create repo2::subset2_datetime /subset2
The main problem is the huge files cache and one way to avoid that is having less files in a repo.
Sure there won't be "inner" dedup between repos any more, but you will still have historical dedup inside each repo.
ok, makes sense.
Last thing: Is it possible to force borg to "flush" the files cache? Say I went and shuffled the data around now and reduced the number of files it would need to back up each day but wanted to keep backing up to the same repo, would I be able to tell borg to forget the file cache and start over?
You can just truncate the file.
~/.cache/borg/<repository ID>/files by default.
The files cache works good enough for "home" ratios of storage-to-RAM, but because it scales linearly with the amount of data and number of files backed up it doesn't work so well when there are much more files than "usual" or a lot of storage connected to one node.
Perfect!
Thanks folks, I think I have a plan now.
@Phuzzy112: as noted by @infectormp, I'm going through something very similar to this on #4869.
@Phuzzy112, if you are still around, can you please comment on how your situation progressed since your last post here (ie, did you solve it totally by adding more RAM, or by disabling the files cache, and/or by segmenting the backup set, etc)?
Thanks in advance, -- Durval.