borgwarehouse icon indicating copy to clipboard operation
borgwarehouse copied to clipboard

Add API endpoint and UI button to compact repo

Open Forceu opened this issue 9 months ago • 6 comments

This PR adds a button and an API endpoint to compact a repo and will close #222

The new api endpoint is POST /api/v1/repositories/[id]/compact. By default the call only initiates compacting and returns 200, if the parameter await is set to true, it will only return after compacting and an additional storage calculation is done.

Compacting can be disabled on append-only repos with the env DISABLE_COMPACT_APPEND_ONLY.

One drawback with compacting is however, that after the process is finished, it registers as a change. This means, a notification might not be send, if a future backup is not made and the notification period was exceeded. I think it is the same with borgbase and there is not really a way around it (other than saving the last date before compacting).

No tests or documentation were created / altered in this PR.

Forceu avatar May 14 '25 12:05 Forceu

@Ravinou The PR is ready for review now. Please note that I changed the gear icon to a pencil in the repo overview, as I think with two buttons it looks better. In case you prefer the old gear icon, let me know and I will revert it back.

Forceu avatar May 15 '25 13:05 Forceu

Thanks, I will study this later (no more time today :D ).

Note that :

  • shell must be tested with bats, like all other shells
  • API must be testes with vitest, like all other api

We have to manage the competing compacts well.

As for the modification date, this will modify the last backup date. After that, it's indicated everywhere that it's a date of last “modification” in borgwarehouse, and compacting is still a manual action. So I don't see any problem with that, I'll add it to the documentation.

Finally, I'll have to do some tests with the borgbackup CLI and read their documentation to be sure of the different types of return from this command.

It's a big feature. I've created the feat/compact branch.

Ravinou avatar May 18 '25 10:05 Ravinou

  • shell must be tested with bats, like all other shells
  • API must be testes with vitest, like all other api

I can give that a try. I have never used bats or vitest (and don't have a lot of experience with TS either), but I guess I can look through the existing scripts

We have to manage the competing compacts well.

I assume during a compacting action, the repository is locked and no other action can be performed. I will test that later on. However it would be nice to have an indication once compaction is done, if an async call was made.

As for the modification date, this will modify the last backup date. After that, it's indicated everywhere that it's a date of last “modification” in borgwarehouse, and compacting is still a manual action. So I don't see any problem with that, I'll add it to the documentation.

The only problem would be if someone was running a cronjob fairly regularly to compact the repos with the API call. But a note in the documentation should be sufficient I assume.

Forceu avatar May 18 '25 10:05 Forceu

@Ravinou Are the tests sufficient or shall I change anything? :)

Forceu avatar Jun 10 '25 09:06 Forceu

I haven't forgotten you. This summer's vacation, coming up in a few weeks, should help me find some time to move forward. Thank you for your patience 🙏

Ravinou avatar Jul 05 '25 18:07 Ravinou

Hope you had a good holiday! Is there anything I can do to help with this PR?

I'm excited to see it in action and reclaim some much-needed storage space.

hozza avatar Aug 08 '25 11:08 hozza