Ejemplo n.º 1
0
// Dump yields a database dump of the keyspace we manage. It will be contained
// in a tarball based on the timestamp of the dump. If a dir is provided, it
// will be placed under that directory.
func (c *Client) Dump(dir string) (string, error) {
	resp, err := c.client.Get(context.Background(), c.prefix, &client.GetOptions{Sort: true, Recursive: true, Quorum: true})
	if err != nil {
		return "", errored.Errorf(`Failed to recursively GET "%v" namespace from etcd`, c.prefix).Combine(err)
	}

	node := convertNode(resp.Node)

	return db.Dump(node, dir)
}
Ejemplo n.º 2
0
// Dump dumps a tarball made with mktemp() to the specified directory.
func (c *Client) Dump(dir string) (string, error) {
	pairs, _, err := c.client.KV().List(c.Prefix(), nil)
	if err != nil {
		return "", err
	}

	// consul uses a flat namespace so here be some hackery for directories and
	// recursive nodes.
	node := &db.Node{
		Key:   "/" + c.Prefix(), // dump routines expect the slash
		Dir:   true,
		Nodes: []*db.Node{},
	}

	for _, pair := range pairs {
		node.Nodes = append(node.Nodes, &db.Node{
			Key:   "/" + pair.Key,
			Value: pair.Value,
			Nodes: []*db.Node{},
		})
	}

	return db.Dump(node, dir)
}