Skip to content

Instantly share code, notes, and snippets.

@Soulou
Created December 21, 2015 10:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soulou/ab3d8ff1c26312d7bc91 to your computer and use it in GitHub Desktop.
Save Soulou/ab3d8ff1c26312d7bc91 to your computer and use it in GitHub Desktop.
Restore repositories-btrfs of a full BTRFS parition of Docker
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