Created
December 21, 2015 10:05
-
-
Save Soulou/ab3d8ff1c26312d7bc91 to your computer and use it in GitHub Desktop.
Restore repositories-btrfs of a full BTRFS parition of Docker
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 | |
// docker images --no-trunc | awk '{print $1 " " $2 " " $3}' > images_data | |
// go run gen_repositories_btrfs.go images_data | |
import ( | |
"bufio" | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strings" | |
) | |
func main() { | |
content, _ := ioutil.ReadFile(os.Args[1]) | |
contentReader := bytes.NewReader(content) | |
reader := bufio.NewReader(contentReader) | |
images := map[string]map[string]string{} | |
var err error | |
for err == nil { | |
var line []byte | |
line, _, err = reader.ReadLine() | |
if string(line) == "" { | |
break | |
} | |
fields := strings.Split(string(line), " ") | |
imageTags, ok := images[fields[0]] | |
if ok { | |
imageTags[fields[1]] = fields[2] | |
} else { | |
imageTags = map[string]string{fields[1]: fields[2]} | |
} | |
images[fields[0]] = imageTags | |
} | |
header := map[string]interface{}{"Repositories": images} | |
js, _ := json.Marshal(header) | |
fmt.Println(string(js)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment