myENA / consul-backinator

Command line Consul backup and restore utility supporting KVs, ACLs and Queries
Mozilla Public License 2.0
226 stars 22 forks source link

restore with prefix option gives misleading result #5

Closed vkhatri closed 8 years ago

vkhatri commented 8 years ago

Hello! I know as per help menu, option prefix is intended only for backup operation. But, when used with restore, the result is misleading.

$ ./consul-backinator-master  --token token -backup -dc localhost -file foo.x.y -prefix foo/x/y
2016/05/09 14:39:31 [Success] Backed up 1 keys from foo/x/y to foo.x.y
Keep your backup (foo.x.y) and signature (foo.x.y.sig) files in a safe place.
You will need both to restore your data.

$ ./consul-backinator-master  --token token -restore -dc localhost -file foo.x.y -prefix foo/x/z
2016/05/09 14:40:04 [Success] Restored 1 keys from foo.x.y to foo/x/z

$ ./consul-backinator-master  --token token -backup -dc localhost -file foo.x.z -prefix foo/x/z
2016/05/09 14:43:31 [Success] Backed up 0 keys from foo/x/z to foo.x.z
Keep your backup (foo.x.z) and signature (foo.x.z.sig) files in a safe place.
You will need both to restore your data.

As shown above, restore result indicated restore of 1 Key to foo/x/z. But, nothing was restored. As you can see i tried to backup foo/x/z and there is nothing to backup. I can confirm there is no key foo/x/z.

I think prefix option should be ignored with a message or should return an error when used with restore.

aaronhurt commented 8 years ago

Right, the prefix option only affects backup and not restore. The equivalent restore option would be the transform. This is mainly due to the parameters accepted by the upstream consul golang api package.

I have two thoughts here:

  1. Add option checking to the backup/restore parts to ensure they are valid as you suggested
  2. Redo the command handling so that backup and restore are actually subcommands with individual options. This would fix the problem but would mean new versions were no longer compatible.
aaronhurt commented 8 years ago

I've pushed some new commits to master that break out the various operations into sub commands. There are now three different modes of operation (backup, restore, dump) that each have their own flag sets. Hopefully this prevents confusion in the future.