Last active
January 10, 2020 12:54
-
-
Save snowmerak/52615f63e6a69703fc555834a1fea62a to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
) | |
func main() { | |
if len(os.Args) < 3 { | |
fmt.Println("too few args.") | |
return | |
} | |
rootName := os.Args[1] | |
targetName := os.Args[2] | |
args := []string{"tar", "cvpzf", targetName} | |
excludeFlag := "--exclude=" | |
excludeNames := []string{targetName, "/proc", "/lost+found", "/media", "/mnt", "/sys", "/run", "/dev"} | |
excludeNames = append(excludeNames, os.Args[3:]...) | |
for _, s := range excludeNames { | |
args = append(args, fmt.Sprintf("%s%s", excludeFlag, s)) | |
} | |
cmd := exec.Command("sudo", args...) | |
cmd.Args = append(cmd.Args, rootName) | |
cmd.Stdout = os.Stdout | |
cmd.Stdin = os.Stdin | |
cmd.Stderr = os.Stderr | |
err := cmd.Run() | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment