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

Feature Request: Upload backup.zip #2599

Closed
tastycrayon opened this issue May 30, 2023 · 4 comments
Closed

Feature Request: Upload backup.zip #2599

tastycrayon opened this issue May 30, 2023 · 4 comments

Comments

@tastycrayon
Copy link

tastycrayon commented May 30, 2023

Recently, I migrated my app to GCP. After fresh install, I wanted to migrate the entire pb_data.

  1. One way was to directly upload the file there. But this does not seem feasible, because it is in my GitHub.
  2. I could just create a separate directory for pb_data and put the files there manually, but I think this approach below will be much better.

Example:
image

My duct tape solution

(it is not related to the feature requested)
As of now, I have created an endpoint which manually puts uploaded file to pb_data/backups folder. But it would be so much nicer to have an upload option built in to the backup section, similar to the image above.

app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
		e.Router.POST("/upload", handleUpload, apis.RequireAdminAuth(), apis.ActivityLogger(app))
		return nil
})

func handleUpload(c echo.Context) error {
	backupPath := filepath.Join(app.RootCmd.Flag("dir").Value.String(), "backups")
	file, err := c.FormFile("file")
	if err != nil {
		return err
	}
	src, err := file.Open()
	if err != nil {
		return err
	}
	defer src.Close()
	// Destination
	if err := os.MkdirAll(backupPath, 0777); err != nil {
		return apis.NewApiError(400, "failed upload", err)
	}
	dst, err := os.Create(filepath.Join(backupPath, file.Filename))
	if err != nil {
		return apis.NewApiError(400, "failed upload", err)
	}
	defer dst.Close()

	// Copy
	if _, err = io.Copy(dst, src); err != nil {
		return apis.NewApiError(400, "failed upload", err)
	}

	return c.HTML(http.StatusOK, fmt.Sprintf("<p>File %s uploaded successfully.</p>", file.Filename))
}

Full code link here

Possible Pitfall

  1. The uploaded backups might also need proper versioning, as they might not be compatible.
@ganigeorgiev
Copy link
Member

Something similar was requested in #2547.

It exists in my todo to consider it at later stage, but for now is left aside.

@nicosql
Copy link

nicosql commented Jun 3, 2023

@ganigeorgiev If it matters, I don't like this solution at all lol, I'm a DBA by trade and an app that would ingest its own database (backup or not) raises red flags simply from an optics perspective and could hurt adoption.

Maybe I'm old school but certain things should be kept external to the application.

I think this would instead be better handled by some helpful additions to the docs with suggestions, maybe some example scripts or services that play well with SQLite (aka Minio / Litestream etc..).

@oSethoum
Copy link

oSethoum commented Jun 16, 2023

@pookiepats as a developer who will be managing the admin panel, you can restore the backup in many ways, but if we assume that the final client ( non technical person ) who will be administrating the application from the admin panel, a simpler way such as the one suggested by @tastycrayon is perfect.

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Aug 28, 2023

I've added in the develop branch option to upload a backup from the Admin UI and it will be available with the next v0.18.0 release (there are no ETAs yet).

For performance reason we currently validate only the mimetype of the file (aka. it needs to be a zip) and whether a backup with the uploaded filename already exists.
Checks whether the backup archive is valid and compatible are performed only during the restore action when we are extracting the zip file.

The JS and Dart SDKs were also updated in their respective develop branches to include a new pb.backups.upload(file) action.

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

No branches or pull requests

4 participants