When backing up a repository, the current code loads all the documents into memory and then writes them to the backup files. This does not scale when there are lots of documents and will cause OOM errors.
When restoring a repository, the entire restore operation is performed inside a single, large transaction. While this operation should be atomic, this approach will not work for a large number of documents and will cause OOM errors.
We should try to perform both operations in batches (while still preserving consistency constraints in the case of restore) in order to avoid memory pressure.