-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package backup | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/yuk7/wsldl/lib/utils" | ||
) | ||
|
||
//Execute is default run entrypoint. | ||
func Execute(name string, args []string) { | ||
opttar := false | ||
optreg := true | ||
switch len(args) { | ||
case 0: | ||
opttar = true | ||
optreg = true | ||
|
||
case 1: | ||
switch args[0] { | ||
case "--tar": | ||
opttar = true | ||
case "--reg": | ||
optreg = true | ||
} | ||
|
||
default: | ||
utils.ErrorExit(os.ErrInvalid, true, true, false) | ||
} | ||
|
||
if optreg { | ||
lxguid, err := utils.WslGetUUID(name) | ||
if err != nil { | ||
utils.ErrorExit(err, true, true, false) | ||
} | ||
regexe := os.Getenv("SystemRoot") + "\\System32\\reg.exe" | ||
regpath := "HKEY_CURRENT_USER\\" + utils.LxssBaseKey + "\\" + lxguid | ||
_, err = exec.Command(regexe, "export", regpath, "backup.reg", "/y").Output() | ||
if err != nil { | ||
utils.ErrorExit(err, true, true, false) | ||
} | ||
} | ||
if opttar { | ||
wslexe := os.Getenv("SystemRoot") + "\\System32\\wsl.exe" | ||
_, err := exec.Command(wslexe, "--export", name, "backup.tar").Output() | ||
if err != nil { | ||
utils.ErrorExit(err, true, true, false) | ||
} | ||
} | ||
} | ||
|
||
// ShowHelp shows help message | ||
func ShowHelp(showTitle bool) { | ||
if showTitle { | ||
println("Usage:") | ||
} | ||
println(" backup [contents]") | ||
println(" - `--tar`: Output backup.tar to the current directory") | ||
println(" - `--reg`: Output settings registry file to the current directory") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters