Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore deleted files too #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

restore deleted files too #28

wants to merge 1 commit into from

Conversation

alive
Copy link

@alive alive commented Jan 19, 2023

context:
mkdir foo/, mkdir foo/bar/, touch foo/bar/file
gb backup foo/
rm -r foo/bar/
gb backup foo/

now:
gb restore foo/bar/ will fail without timestamp provided, even though it's pretty clear (?) what gb should restore - namely the last version of bar/

This is just a proof of concept of what a solution might look like.

@leijurv
Copy link
Owner

leijurv commented Jan 20, 2023

well wait, i thought the whole idea of your issue was that it's annoying to restore files one at a time with a timestamp for each. wouldn't this make much more sense if it was per-file rather than per-directory?

also i don't like the GLOB thing. https://github.com/leijurv/gb/blob/master/proxy/proxy.go#L101 in order to glob directory paths containing square brackets you have to do a stupid hack

@leijurv
Copy link
Owner

leijurv commented Jan 20, 2023

I think it can be much simpler tbh, very few lines need to change. I think this is an alternative for QUERY_BASE

const (
	QUERY_BASE = "SELECT files.hash, files.path, files.fs_modified, files.permissions, MAX(files.start) AS start, sizes.size FROM files INNER JOIN sizes ON files.hash = sizes.hash WHERE files.path GLOB ? GROUP BY files.path"
)

(it isn't quite right because of how I put the files.path GLOB ? in the query rather than appending it to the end, but this is just to get across the idea)

the trick here is that if you put in max(files.start) and group by files.path sqlite will do something hilarious which is to pick the row with the highest value for files.start for every files.path. the other columns like files.hash will be chosen to be the correct values for that row where files.start was maximized. how convenient, that's exactly what we want! (this is a sqlite only thing, see https://sqlite.org/lang_select.html#simple_select_processing section 2.5 Bare columns in an aggregate query if you don't believe me)

@5HT2
Copy link

5HT2 commented Jan 20, 2023

this is a sqlite only thing

tfw postgresql user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants