Caching in restic - large retrieve times on some cloud storages

Hi there,

I’m just starting to try out restic as it seem like a perfect solution for my personal backups.

However I have an issue about my cloud storage and wonder why the caching in restic is not solving the problem.

I’m using a storage which is cheap but has a really bad SLA on retrive times. In my case it’s OVH Cloud Archive OVH Cloud Archive but it seems that also AWS S3 Glacier has similiar issues. They guarantee that you get back your objects, but you may have to wait up to 12 hours to get a single object.

Now, about caching:
It seems to me that restic caches snapshot files, index files and data files corresponding to metadata. This is great and speeds up the usual backup quite a lot. However, the config file and the key files are not cached but always retrieved from the storage. Of course we are not talking about big files and with usual storage backends this shouldn’t be a performance issue. However, with OVH Cloud Archive backup regularily times out when the config file and the used key file have large retrieve times… :frowning:

So, is there a reason why the config-file and the key files are excluded from the cache?
Or the other way round: Is there some reason which prevents adding config-file and key-files to the cache?

Cheers,
Alex

Restic assumes the same repository can be accessed by multiple systems concurrently and does not cache the config and key files to avoid data corruption. For example, if repository config changes, using cached config file during backup may result in invalid/unusable files written to the repository. And lock files cannot be cached at all.

@alexweiss Why do you not keep your backups on a storage that doesn’t have a latency of 12 hours? Is it really that important to save a few bucks, or what’s the point of the current approach?

It would be cool (but IMO hardly a need to have) if restic could store config and locks in one place and the actual data and other things in another place :slight_smile:

Hi,
thank you very much for your answers!
@ifedorenko Thanks for the explanation!
However, I still do not see why keys are not cached as the filename is the SHA256 hash and therefore changed keys get different filenames. Or is the trouble that you can’t remove keys if they are still cached somewhere?
According to Repo design I don’t see how the config file would change for a existing repo. ATM only the chunkger polynomial is saved and changing this would kill the deduplication…?!?

@rawtaz The latency is the trade-off for cheap storage :slight_smile: We are taking about a factor of about 5 for storage costs. And the cost depends on the size. So the saving depends on the size and might be some bucks for a small size and even quite some bucks for a bigger size :wink:
In my case I would like to save the money and the trade-off having a 12 hour latency for restoring would be ok. However not ok having a 12 hour latency for backing up… :cold_face:

Cheers, Alex

OVH Cloud Archive charges for incoming and outgoing traffic. Depending on your use case and the amounts of data this can add up really quickly.

IMHO OVH Cloud Archive is suitable for a safety copy of a restic repository but not for a primary repository which is accessed frequently. Some of the reasons why such a storage type is not suitable for restic have been discussed in this thread about S3 Glacier Deep Archive.

I don’t understand enough about restic key usage to comment why they are not cached, but config file contains version attribute, which I believe is meant for forward compatibility should repository format change.

@alexweiss Here’s my approach to using Amazon’s ultra-low-cost Amazon Glacier Deep Archive while maintaining reasonable performance in most situations.

I have a nightly backup process that performs a backup to low-cost local storage nightly, and performs a weekly prune/forget. Every day after that backup, my backup process then performs an aws s3 sync to synchronize my local repository to AWS S3. This is a delta-based synchronization, so it runs very quickly, finding and copying changed files only.

My S3 bucket has lifecycle rules defined on it, so that any files in the data/ directory are migrated to AWS Glacier Deep Archive after seven days. (I don’t bother migrating the index, keys or snapshots to Glacier… I just keep them in S3.)

This has been very effective for me: Costs are far lower than my previous provider (wasabi.com), and restored are performed from local storage so I get great performance. I expect that I will never need to retrieve from Glacier unless I experience a catastrophic failure onsite (of both my primary storage and my backup storage).

@David Thanks for sharing your solution!
Actually the idea of using S3 lifecycle rules is very charming - in your case you could even use S3 for normal backup as all regularily used files are either cached by restic or stay in normal S3 storage :slight_smile: I see the trouble with prune but maybe pruning is not first priority for real low-cost-storage…

However I don’t like the idea of using a local repository and syncing it to a remote storage. By my opinion this is kind of equivalent of using a cache and caching everything . I’d prefer the caching option because

  • ideally you can finetune which parts you really need cached (and hence you can save local storage if you need to)
  • the cache is a (partial) copy of the (remote) repository which is written independently and after the (remote) repository. That guarantees that your (remote) repository stays in good shape in some wired situations. I already had the situation that a broken USB Hub destroyed my backup data but didn’t prevent the broken backup from syncing to a remote storage ouch!

About the caching implementation I just digged a little bit into the code and did some debugging and finally found some answers to my original questions:

  • The cache is organized by the repo ID
  • Hence the key files and config files can’t be cached as they are needed to determine the repo ID :smirk:
  • standard operation for e.g. lock files, key files, index files, snapshot files is to get a list of all files and then access the files by the SHA256 ID. The list is done in the real backend (as you never know if the cache is complete) and then read all or the needed files. The actual reading is either done in the cache or (if not present or Type not cached) in the backend. BTW: most ultra-cheap storages (S3 glacier, OVH Cloud Archive) don’t have any “latency” issue with listing…

During backup operation, following data is read:

  • keys and config (from the backend, see above)
  • locks (from the backend)
  • snapshot, index, maybe metadata (from cache or backend)

My proposal for improving the situation with hours of read-latency is:

  • Add an option to organize the cache by the repo string (given e.g. by the -r paramter) to make caching of keys and config possible
  • Add options which allow choosing what is cached. For the low-cost-storages I have in mind this would include keys, config and lock files. Maybe an option to cache all data files would be also nice to cover the setting of @David

I will add an issue in github and start working on the implementation.

I think of it differently. I don’t consider the local copy a cache, I think of the remote copy as an offsite backup of my repository.

Experts and IT Operations standards overwhelmingly recommend the “3-2-1 strategy” for backup. In this strategy all valuable data should have 3 copies: 2 onsite and 1 offsite). The approach I described fits that strategy, with the local repository as the second onsite copy, and the cloud repository as the offsite copy.

One downside to Glacier Deep Archive is you pay for at least six months of storage regardless of how long the object is stored, Glacier is three months. That means if you back up data that is deleted within that time you’re over-paying for it. However, given that deep archive is 23X cheaper than standard and 12X cheaper than IA class it probably makes sense. I’m currently putting my data into IA class, but I might move it out to Glacier Deep Archive class.

If you regularly create then delete large amounts of data then you might be best off transitioning to IA class immediately, then moving to Glacier / Deep Archive class after maybe a month. If you create but rarely delete then you might as well push it to Glacier / Deep Archive fairly quickly.

I keep versions of objects in my Restic S3 bucket, to protect against something like a virus overwriting the data. I delete old versions after a year.

If you use any storage that is not immediately available (such as Glacier or GDA) then make sure you run every backup with --force since some tree objects in the parent snapshot may be in transitioned (and hence inaccessible) packs.

In fact, many commands would be affected. Here is my understanding of how this would affect each restic command (commands not listed are not affected):

Command Affect of inaccessible packs
backup Must run with --force since trees in the parent may be inaccessible.
check Cannot use at all because this needs every pack header.
diff Will fail when any snapshot references an object that in a transitioned pack.
dump Will fail when any object along the path to the named file is in a transitioned pack.
find Will probably fail to run at all or may produce incomplete output.
forget Cannot use --prune for the reasons given below for the prune command.
ls Will probably fail with most snapshots when an inaccessible tree is needed.
migrate Will fail if it needs to make any changes to transitioned packs.
mount Will succeed but I/O errors may result when reading from the mounted virtual filesystem as inaccessible objects are needed.
prune Cannot use at all because this needs every pack header.
rebuild-index Cannot use at all because this needs every pack header.
recover Cannot use at all because this needs every pack header.
restore Can use only with data that has not been transitioned.
stats Will likely fail if any snapshot named has transitioned objects.

In particular: a huge caveat to restore is that it can’t give you a list of packs it needs because it must first crawl all the trees to locate all of the objects. It will fail on a specific pack. You can go restore that one pack, then it will fail on another pack, and so on.

The only way to restore (or use most of these commands) with any confidence that anything will work would be to initiate a restore of every transitioned object in the repository. This could be very expensive.

If you can live with the above limitations, you might be able to use Glacier or GDA tiers. For me it’s not even close to worth the hassle.

Note that this all assumes you are only transitioning objects in the data directory/prefix. You must not transition any other objects or restic likely won’t even run against the repository.

1 Like

If I understood it right, restic does cache alle data files (=packs) that contains a tree object. Or did I get something wrong? :flushed:

Therefore I guess your list can be changed if you assume that you have a complete cache where all packs containing tree objects are included.

Under that assumption only packs with data blobs are inaccessible and I would change the table as follows:

Command Affect of inaccessible data-only packs
backup should fully work
check should work when using --with-cache
find should fully work
ls should fully work
stats should fully work

Moreover I’m not sure if the prune problem is mainly based on the fact, that prune always does include something like rebuild-index…

Here I also disagree :wink: . I think it would be possible the produce that list. However, I agree that the current implementation does assume that everything can be accessed immediately and would probable fail like you describe it.

Again, I disagree :wink: :wink:
The other objects must be either immediately accessible or in the cache. For snapshots and indices caching is already implemented. For config, keys and locks I’m trying to change the implementation, see my comment above (#9).

The cache is not something that is intended to make restic operate correctly if files are not accessible, it is only for performance IMO. I would strongly caution you against depending on the presence of the cache for restic to operate.

In particular, this technique is likely to break down whenever multiple cache directories are used (such as when backing up to the same repository from multiple machines).

Prune does multiple things. I merely listed the first that will cause it to fail. It must also crawl every tree in every pack and rewrite packs. Aside from check --read-data, prune probably reads the most data of any restic command.