{"record":{"id":"8d50eb2de617761d","repo":"juicedata/juicefs","slug":"restore-command-requires-administrator-or-elevated","errorCode":null,"errorMessage":"restore command requires Administrator or elevated privilege on Windows","messagePattern":"restore command requires Administrator or elevated privilege on Windows","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/restore.go","lineNumber":47,"sourceCode":"$ juicefs restore redis://localhost/1 2023-05-10-01`,\n\t\tFlags: []cli.Flag{\n\t\t\t&cli.BoolFlag{\n\t\t\t\tName:  \"put-back\",\n\t\t\t\tUsage: \"move the recovered files into original directory\",\n\t\t\t},\n\t\t\t&cli.IntFlag{\n\t\t\t\tName:  \"threads\",\n\t\t\t\tValue: 10,\n\t\t\t\tUsage: \"number of threads\",\n\t\t\t},\n\t\t},\n\t}\n}\n\nfunc restore(ctx *cli.Context) error {\n\tsetup0(ctx, 2, 0)\n\tif runtime.GOOS == \"windows\" && !utils.IsWinAdminOrElevatedPrivilege() {\n\t\treturn fmt.Errorf(\"restore command requires Administrator or elevated privilege on Windows\")\n\t}\n\tif os.Getuid() != 0 && runtime.GOOS != \"windows\" {\n\t\treturn fmt.Errorf(\"only root can restore files from trash\")\n\t}\n\tremovePassword(ctx.Args().Get(0))\n\tm := meta.NewClient(ctx.Args().Get(0), nil)\n\t_, err := m.Load(true)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor i := 1; i < ctx.NArg(); i++ {\n\t\thour := ctx.Args().Get(i)\n\t\tdoRestore(m, hour, ctx.Bool(\"put-back\"), ctx.Int(\"threads\"))\n\t}\n\treturn nil\n}\n\nfunc doRestore(m meta.Meta, hour string, putBack bool, threads int) {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/restore.go#L29-L65","documentation":"The 'restore' command reads and rewrites trash metadata and file attributes, which on Windows requires elevated rights. Before doing anything else, restore checks whether the process runs as Administrator (or an elevated process) via utils.IsWinAdminOrElevatedPrivilege and aborts with this error when it does not. Non-Windows systems are checked separately against root (uid 0).","triggerScenarios":"Running `juicefs restore <meta-url> ...` on Windows from a normal (non-elevated) shell, e.g. a regular cmd/PowerShell window or a non-elevated scheduled task; runtime.GOOS == \"windows\" and IsWinAdminOrElevatedPrivilege() returns false.","commonSituations":"Double-clicking or scripting juicefs.exe without 'Run as administrator'; CI agents on Windows runners lacking elevation; an elevated terminal requirement forgotten after switching to a standard user account.","solutions":["Relaunch the shell or command with 'Run as administrator' and rerun the restore.","From an elevated PowerShell: Start-Process juicefs -ArgumentList 'restore ...' -Verb RunAs.","For scheduled tasks, enable 'Run with highest privileges' for the task.","Alternatively run the restore from a root account on a Linux client pointed at the same metadata engine."],"exampleFix":"// before (non-elevated PowerShell)\njuicefs restore redis://:pass@host:6379/1 /trash-file\n// after (elevated PowerShell)\nStart-Process -Verb RunAs -Wait juicefs -ArgumentList 'restore','redis://:pass@host:6379/1','/trash-file'","handlingStrategy":"validation","validationCode":"# PowerShell pre-check before running restore\n$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\nif (-not $isAdmin) { throw \"Run this script from an elevated (Administrator) shell.\" }","typeGuard":null,"tryCatchPattern":"err := exec.Command(\"juicefs\", \"restore\", metaURL, target).Run()\nif err != nil && strings.Contains(err.Error(), \"requires Administrator\") {\n    // relaunch elevated via powershell Start-Process -Verb RunAs\n}","preventionTips":["Open an elevated terminal (Run as administrator) before any trash restore work on Windows.","Set scheduled tasks/CI jobs to 'Run with highest privileges' when they call restore.","Check elevation programmatically with IsWinAdminOrElevatedPrivilege-style logic before launching.","Prefer Linux root clients for scripted restores when elevation on Windows is impractical."],"tags":["windows","admin","privilege","trash","cli"],"backgroundTag":"permission-denied","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}