You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: base_backup.go
    path of file: ./repos/pocketbase/core
    
    the code of the file until where you have to start completion: package core

import (
	"context"
	"errors"
	"fmt"
	"io"
	"log/slog"
	"os"
	"path/filepath"
	"runtime"
	"sort"
	"time"

	"github.com/pocketbase/pocketbase/daos"
	"github.com/pocketbase/pocketbase/models"
	"github.com/pocketbase/pocketbase/tools/archive"
	"github.com/pocketbase/pocketbase/tools/cron"
	"github.com/pock
    
func (app *BaseApp) RestoreBackup(ctx context.Context, name string) error {
	if runtime.GOOS == "windows" {
		return errors.New("restore is not supported on windows")
	}

	if app.Store().Has(StoreKeyActiveBackup) {
		return errors.New("try again later - another backup/restore operation has already been started")
	}

	app.Store().Set(StoreKeyActiveBackup, name)
	defer app.Store().Remove(StoreKeyActiveBackup)

	fsys, err := app.NewBackupsFilesystem()
	if err != nil {
		return err
	}
	defer fsys.Close()

	fsys.SetContext(ctx)

	// fetch the backup file in a temp location
	br, err := fsys.GetFile(name)
	if err != nil {
		return err
	}
	defer br.Close()

	// make sure that the special temp directory exists
	// note: it needs to be inside the current pb_data to avoid "cross-device link" errors
	localTempDir := filepath.Join(app.DataDir(), LocalTempDirName)
	if err := os.MkdirAll(localTempDir, os.ModePerm); err != nil {
		return fmt.Errorf("failed to create a temp dir: %w", err)
	}

	// create a temp zip file from the blob.Reader and try to extract it
	tempZip, err := os.CreateTemp(localTempDir, "pb_restore_zip")
	if err != nil {
		return err
	}
	defer os.Remove(tempZip.Name())

	if _, err := io.Copy(tempZip, br); err != nil {
		return err
	}

	extractedDataDir := filepath.Join(localTempDir, "pb_restore_"+security.PseudorandomString(4))
	defer os.RemoveAll(extractedDataDir)
	if err := archive.Extract(tempZip.Name(), extractedDataDir); err != nil {
		return err
	}

	// ensure that a database file exists
	extractedDB := filepath.Join(extractedDataDir, "data.db")
	if _, err := os.Stat(extractedDB); err != nil {
		return fmt.Errorf("data.db file is missing or invalid: %w", err)
	}

	// remove the extracted zip file since we no longer need it
	// (this is in case the app restarts and the defer calls are not called)
	if err := os.Remove(tempZip.Name()); err != nil {
		app.Logger().Debug(
			"[RestoreBackup] Failed to remove the temp zip backup file",
			slog.String("file", tempZip.Name()),
			slog.String("error", err.Error()),
		)
	}

	// root dir entries to exclude from the backup restore
	exclude := []string{LocalBackupsDirName, LocalTempDirName}

	// move the current pb_data content to a special temp location
	// that will hold the old data between dirs replace
	// (the temp dir will be automatically removed on the next app start)
	oldTempDataDir := filepath.Join(localTempDir, "old_pb_data_"+security.PseudorandomString(4))
	if err := osutils.MoveDirContent(app.DataDir(), oldTempDataDir, exclude...); err != nil {
		return fmt.Errorf("failed to move the current pb_data content to a temp location: %w", err)
	}

	// move the extracted archive content to the app's pb_data
	if err := osutils.MoveDirContent(extractedDataDir, app.DataDir(), exclude...); err != nil {
		return fmt.Errorf("failed to move the extracted archive content to pb_data: %w", err)
	}

	revertDataDirChanges := func() error {
		if err := osutils.MoveDirContent(app.DataDir(), extractedDataDir, exclude...); err != nil {
			return fmt.Errorf("failed to revert the extracted dir change: %w", err)
		}

		if err := osutils.MoveDirContent(oldTempDataDir, app.DataDir(), exclude...); err != nil {
			return fmt.Errorf("failed to revert old pb_data dir change: %w", err)
		}

		return nil
	}

	// restart the app
	if err := app.Restart(); err != nil {
		if revertErr := revertDataDirChanges(); revertErr != nil {
			panic(revertErr)
		}

		return fmt.Errorf("failed to restart the app process: %w", err)
	}

	return nil
}