Skip to content

Instantly share code, notes, and snippets.

@bestie
Created April 7, 2025 10:26
Show Gist options
  • Save bestie/99bc59f0f5d8cecc4df9e40910bfdced to your computer and use it in GitHub Desktop.
Save bestie/99bc59f0f5d8cecc4df9e40910bfdced to your computer and use it in GitHub Desktop.
Earthly auto-skip DB dumper
FROM golang:1.24-bookworm
WORKDIR /app
COPY dumper.go .
RUN go mod init boltdbdumper && \
go get go.etcd.io/bbolt@latest && \
go mod tidy && \
go build -o dumper
CMD ["./dumper"]
#!/bin/bash
set -euxo pipefail
dbfile=$(readlink --canonicalize "$1")
docker build --tag earthly-auto-skip-db-dumper .
docker run \
--rm \
--interactive --tty \
--env "DB_FILE=target.db" \
--volume "$dbfile:/app/target.db" \
earthly-auto-skip-db-dumper
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
bolt "go.etcd.io/bbolt"
)
func main() {
path := os.Getenv("DB_FILE")
if path == "" {
log.Fatal("DB_FILE environment variable is not set")
}
db, err := bolt.Open(path, 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
err = db.View(func(tx *bolt.Tx) error {
return tx.ForEach(func(bname []byte, b *bolt.Bucket) error {
fmt.Printf("Bucket: %s\n", bname)
return b.ForEach(func(k, v []byte) error {
fmt.Printf(" %s => %s\n", hex.EncodeToString(k), v)
return nil
})
})
})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment