Is there any way to restore a branch that was acci...
# help
u
Is there any way to restore a branch that was accidentally deleted? Manually querying the database is also acceptable. Or is there any way to prevent a branch from being deleted?
a
If you know its commit digest, you can just check out a branch from that commit digest. You can even use the same name. For instance, if you know the old digest was
c0ffee
than you could
Copy code
lakectl branch create <lakefs://my-repo/my-branch> -s <lakefs://my-repo/c0ffee>
Finding that branch will be rather more difficult. It's probably not in KV if you deleted it. If I had to find a deleted branch, I would probably search for its commit by using the commit metadata.
u
@Ariel Shaqed (Scolnicov) Do you mean setting commit metadata when creating a commit, and then polling all commits to find the latest commit for the corresponding branch? But a commit may appear in multiple branches at the same time.
a
Yes, exactly. Do you know the commit ID? If you do then you can just create a branch on that commit ID. So the problem is finding the commit ID. If the commit was also on another branch then you can find it. Otherwise you will need to search KV, we do not currently provide timing for that. You'll need to know something about that commit to find it: message, time, user metadata, any such information can help.
Regarding preventing branch deletion check out branch protection.
u
@Ariel Shaqed (Scolnicov) Got it, thank you! But currently branch protection does not include deleting branches?
a
Indeed, I was wrong - branch protection does not prevent branch deletion. So I do not know a way to do this on lakeFS OSS. We never implemented this suggestion to implement a reflog (and even if we did, it would require some more work to fix this). If you're on lakeFS Enterprise, you could remove permissions to delete branch.
Back to your original question: Are you asking about an actual branch you just deleted, or about recovering from a future possibility? If you are looking for an actual deleted branch: please collect all information you do have about the commit(s) on that branch. Can you estimate how many commits you have, roughly (hundreds / tens of thousands / millions / hundreds of millions)? I may be able to help you find it if you have enough information.
u
@Ariel Shaqed (Scolnicov) Thank you very much! I want to prevent branches from being accidentally deleted. The only solution I can think of is to manually traverse pgsql based on the commit information to find the relevant commit. If I am wrong, please correct me, and I would be happy to hear other solutions you can share.
u
Hi @HT
Spoke with Tino today - it sounds like as long as the GC didn't run this can be done today via the CLI (while it can't be done via the UI of course).
Is there any specific instruction on this?
h
I don't know ... I am neither that user in the github issue, neither from LakeFS. My guess is as Ariel mentioned above: if you know the commit that was the HEAD of you deleted branch, then you can create a branch from that commit, thus restoring the deleted branch. And to create a branch from a commit, you need the python SDK, or API, or lakectl, ... but not via the current LakeFS WebUI. As I understand, the LakeFS WebUI can only create branch from and existing branch, but not from an arbitrary commit ID.
👍 1
a
@HT is (as always 😸) correct. If you know the commit ID, you can just re-create the same branch from that commit ID. This is not possible from the GUI, but
lakectl branch create <lakefs://my-repo/the-branch> -s 5ca1ab1e
, for instance, will create branch
the-branch
to start at the commit whose ID starts with the hex digits
5ca1ab1e
.