etcd-backup

etcd-backup is a simple, efficient and lightweight command line utility to backup and restore etcd keys.

Dependencies

etcd-backup has only one dependency: go-etcd the golang offical library for ETCD

Installation

Installation composed of 3 steps:

  • Install go
  • Download the project git clone git@github.com:fanhattan/etcd-backup.git
  • Download the dependency go get github.com/coreos/go-etcd/etcd
  • Build the binary cd etcd-backup and then go install

Dumping

Usage

$ etcd-dump dump

This is the easiest way to dump the whole etcd keyspace. Results will be stored in a json file etcd-dump.json in the directory where you executed the command.

The default Backup strategy for dumping is to dump all keys and preserve the order : keys:["/"], recursive:true, sorted:true The backup strategy can be overwritten in the etcd-backup configuration file. See fixtures/backup-configuration.json

Command line options and default values

-config Mandatory etcd-backup configuration file location, default value: "backup-configuration.json". See Configuration section for more information.
-retries Number of retries that will be executed if the request fails, default value is 5.
-etcd-config etcd client configuration file location, default value: "etcd-configuration.json". See fixtures folder for an example.
-file Location of the dump file data will be stored in, default value: "etcd-dump.json".

$ etcd-dump -config=myBackupConfig.json -retries=2 -etcd-config=myClusterConfig.json -file=result.json dump

The dump.keys supports different configurations:

{ "key": "/", "recursive": true }

Recursively dump all the keys inside /.

{ "key": "/myKey" }

Dump only the key /myKey.

Dump File structure

Dumped keys are stored in an array of keys, the key path is the absolute path. By design non-empty directories are not saved in the dump file, and empty directories do not contain the value key:

[{ "key": "/myKey", "value": "value1" },{ "key": "/dir/mydir/myKey", "value": "test" }, {"key": "/dir/emptyDir"}]

Restoring

Usage

$ etcd-dump restore

Restore the keys from the etcd-dump.json file.

Restore now supports Strategy, you can restore some part of the dumpfile or the entire dump if you want to.

{ "backupStrategy": { "keys": ["/"], "recursive": true } }

Will Recursively restore all the keys inside /.

{ "backupStrategy": { "keys": ["/myKey"], "recursive": true } }

Will only restore the keys under /myKey.

Command line options and default values

-config Mandatory etcd-backup configuration file location, default value: "backup-configuration.json". See Configuration section for more information.
-concurrent-requests Number of concurrent requests that will be executed during the restore (restore mode only), default value is 10.
-retries Number of retries that will be executed if the request fails, default value is 5.
-etcd-config etcd client configuration file location, default value: "etcd-configuration.json". See fixtures folder for an example.
-file Location of the dump file data will be loaded from, default value: "etcd-dump.json".

$ etcd-dump -config=myBackupConfig.json -retries=2 -etcd-config=myClusterConfig.json -file=dataset.json -concurrent-requests=100 restore