{"action":"created","comment":{"url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/comments/23614194","id":23614194,"diff_hunk":"@@ -25,20 +25,41 @@ class EcKeyExport < Chef::Knife\n \n       include Knife::EcKeyBase\n \n-      banner \"knife ec key export [PATH]\"\n+      banner \"knife ec key export [USER_DATA_PATH] [KEY_DATA_PATH]\"\n \n       def run\n         if config[:sql_user].nil? || config[:sql_password].nil?\n           load_config_from_file!\n         end\n \n-        path = @name_args[0] || \"key_dump.json\"\n-        export(path)\n+        # user_data_path defaults to key_dump.json to support\n+        # older knife-ec-backup exports\n+        user_data_path = @name_args[0] || \"key_dump.json\"\n+        key_data_path =  @name_args[1] || \"key_table_dump.json\"\n+\n+        export(:users, user_data_path) unless config[:skip_users_table]\n+\n+        begin\n+          export_keys(key_data_path) unless config[:skip_keys_table]\n+        rescue Sequel::DatabaseError => e\n+          if e.message =~ /^PG::UndefinedTable/\n+            ui.error \"Keys table not found. The keys table only exists on Chef Server 12.\"\n+            ui.error \"Chef Server 11 users should use the --skip-keys-table option to avoid this error.\"\n+            exit 1\n+          else\n+            raise\n+          end\n+        end\n+      end\n+\n+      def export_keys(path)\n+        data = db.fetch('SELECT keys_by_name.*, orgs.name AS \"org_name\" FROM keys_by_name LEFT JOIN orgs ON keys_by_name.org_id=orgs.id')","path":"lib/chef/knife/ec_key_export.rb","position":35,"original_position":35,"commit_id":"14d38fc84348d10fd3fdc967bc13ed9bd139aa30","original_commit_id":"14d38fc84348d10fd3fdc967bc13ed9bd139aa30","user":{"login":"marcparadise","id":1130204,"avatar_url":"https://avatars.githubusercontent.com/u/1130204?v=3","gravatar_id":"","url":"https://api.github.com/users/marcparadise","html_url":"https://github.com/marcparadise","followers_url":"https://api.github.com/users/marcparadise/followers","following_url":"https://api.github.com/users/marcparadise/following{/other_user}","gists_url":"https://api.github.com/users/marcparadise/gists{/gist_id}","starred_url":"https://api.github.com/users/marcparadise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcparadise/subscriptions","organizations_url":"https://api.github.com/users/marcparadise/orgs","repos_url":"https://api.github.com/users/marcparadise/repos","events_url":"https://api.github.com/users/marcparadise/events{/privacy}","received_events_url":"https://api.github.com/users/marcparadise/received_events","type":"User","site_admin":false},"body":"This will export only client keys, but from the name it sounds like all is expected? (Unless we created a 'global' org record, but I don't think we did.) ","created_at":"2015-01-27T15:15:53Z","updated_at":"2015-01-27T15:15:53Z","html_url":"https://github.com/chef/knife-ec-backup/pull/59#discussion_r23614194","pull_request_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59","_links":{"self":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/comments/23614194"},"html":{"href":"https://github.com/chef/knife-ec-backup/pull/59#discussion_r23614194"},"pull_request":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59"}}},"pull_request":{"url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59","id":28024797,"html_url":"https://github.com/chef/knife-ec-backup/pull/59","diff_url":"https://github.com/chef/knife-ec-backup/pull/59.diff","patch_url":"https://github.com/chef/knife-ec-backup/pull/59.patch","issue_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/59","number":59,"state":"open","locked":false,"title":"Ssd/chef 12 support","user":{"login":"stevendanna","id":852371,"avatar_url":"https://avatars.githubusercontent.com/u/852371?v=3","gravatar_id":"","url":"https://api.github.com/users/stevendanna","html_url":"https://github.com/stevendanna","followers_url":"https://api.github.com/users/stevendanna/followers","following_url":"https://api.github.com/users/stevendanna/following{/other_user}","gists_url":"https://api.github.com/users/stevendanna/gists{/gist_id}","starred_url":"https://api.github.com/users/stevendanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevendanna/subscriptions","organizations_url":"https://api.github.com/users/stevendanna/orgs","repos_url":"https://api.github.com/users/stevendanna/repos","events_url":"https://api.github.com/users/stevendanna/events{/privacy}","received_events_url":"https://api.github.com/users/stevendanna/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-26T13:02:18Z","updated_at":"2015-01-27T15:15:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d7879d21bbd7bb06cc2d4f00769eaf1191903908","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59/commits","review_comments_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59/comments","review_comment_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls/comments/{number}","comments_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/59/comments","statuses_url":"https://api.github.com/repos/chef/knife-ec-backup/statuses/14d38fc84348d10fd3fdc967bc13ed9bd139aa30","head":{"label":"chef:ssd/chef-12-support","ref":"ssd/chef-12-support","sha":"14d38fc84348d10fd3fdc967bc13ed9bd139aa30","user":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"repo":{"id":13284944,"name":"knife-ec-backup","full_name":"chef/knife-ec-backup","owner":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef/knife-ec-backup","description":"Backup and restore EC in a sane, repository-compatible format using knife-essentials","fork":false,"url":"https://api.github.com/repos/chef/knife-ec-backup","forks_url":"https://api.github.com/repos/chef/knife-ec-backup/forks","keys_url":"https://api.github.com/repos/chef/knife-ec-backup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef/knife-ec-backup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef/knife-ec-backup/teams","hooks_url":"https://api.github.com/repos/chef/knife-ec-backup/hooks","issue_events_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/events{/number}","events_url":"https://api.github.com/repos/chef/knife-ec-backup/events","assignees_url":"https://api.github.com/repos/chef/knife-ec-backup/assignees{/user}","branches_url":"https://api.github.com/repos/chef/knife-ec-backup/branches{/branch}","tags_url":"https://api.github.com/repos/chef/knife-ec-backup/tags","blobs_url":"https://api.github.com/repos/chef/knife-ec-backup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef/knife-ec-backup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef/knife-ec-backup/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef/knife-ec-backup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef/knife-ec-backup/statuses/{sha}","languages_url":"https://api.github.com/repos/chef/knife-ec-backup/languages","stargazers_url":"https://api.github.com/repos/chef/knife-ec-backup/stargazers","contributors_url":"https://api.github.com/repos/chef/knife-ec-backup/contributors","subscribers_url":"https://api.github.com/repos/chef/knife-ec-backup/subscribers","subscription_url":"https://api.github.com/repos/chef/knife-ec-backup/subscription","commits_url":"https://api.github.com/repos/chef/knife-ec-backup/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef/knife-ec-backup/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef/knife-ec-backup/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/comments/{number}","contents_url":"https://api.github.com/repos/chef/knife-ec-backup/contents/{+path}","compare_url":"https://api.github.com/repos/chef/knife-ec-backup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef/knife-ec-backup/merges","archive_url":"https://api.github.com/repos/chef/knife-ec-backup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef/knife-ec-backup/downloads","issues_url":"https://api.github.com/repos/chef/knife-ec-backup/issues{/number}","pulls_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls{/number}","milestones_url":"https://api.github.com/repos/chef/knife-ec-backup/milestones{/number}","notifications_url":"https://api.github.com/repos/chef/knife-ec-backup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef/knife-ec-backup/labels{/name}","releases_url":"https://api.github.com/repos/chef/knife-ec-backup/releases{/id}","created_at":"2013-10-02T22:42:20Z","updated_at":"2014-11-28T18:44:05Z","pushed_at":"2015-01-26T16:32:40Z","git_url":"git://github.com/chef/knife-ec-backup.git","ssh_url":"git@github.com:chef/knife-ec-backup.git","clone_url":"https://github.com/chef/knife-ec-backup.git","svn_url":"https://github.com/chef/knife-ec-backup","homepage":"","size":961,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":5,"forks":5,"open_issues":5,"watchers":4,"default_branch":"master"}},"base":{"label":"chef:master","ref":"master","sha":"df86a83bee5bb92be5ea9088121c06787239eb3c","user":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"repo":{"id":13284944,"name":"knife-ec-backup","full_name":"chef/knife-ec-backup","owner":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef/knife-ec-backup","description":"Backup and restore EC in a sane, repository-compatible format using knife-essentials","fork":false,"url":"https://api.github.com/repos/chef/knife-ec-backup","forks_url":"https://api.github.com/repos/chef/knife-ec-backup/forks","keys_url":"https://api.github.com/repos/chef/knife-ec-backup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef/knife-ec-backup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef/knife-ec-backup/teams","hooks_url":"https://api.github.com/repos/chef/knife-ec-backup/hooks","issue_events_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/events{/number}","events_url":"https://api.github.com/repos/chef/knife-ec-backup/events","assignees_url":"https://api.github.com/repos/chef/knife-ec-backup/assignees{/user}","branches_url":"https://api.github.com/repos/chef/knife-ec-backup/branches{/branch}","tags_url":"https://api.github.com/repos/chef/knife-ec-backup/tags","blobs_url":"https://api.github.com/repos/chef/knife-ec-backup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef/knife-ec-backup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef/knife-ec-backup/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef/knife-ec-backup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef/knife-ec-backup/statuses/{sha}","languages_url":"https://api.github.com/repos/chef/knife-ec-backup/languages","stargazers_url":"https://api.github.com/repos/chef/knife-ec-backup/stargazers","contributors_url":"https://api.github.com/repos/chef/knife-ec-backup/contributors","subscribers_url":"https://api.github.com/repos/chef/knife-ec-backup/subscribers","subscription_url":"https://api.github.com/repos/chef/knife-ec-backup/subscription","commits_url":"https://api.github.com/repos/chef/knife-ec-backup/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef/knife-ec-backup/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef/knife-ec-backup/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef/knife-ec-backup/issues/comments/{number}","contents_url":"https://api.github.com/repos/chef/knife-ec-backup/contents/{+path}","compare_url":"https://api.github.com/repos/chef/knife-ec-backup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef/knife-ec-backup/merges","archive_url":"https://api.github.com/repos/chef/knife-ec-backup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef/knife-ec-backup/downloads","issues_url":"https://api.github.com/repos/chef/knife-ec-backup/issues{/number}","pulls_url":"https://api.github.com/repos/chef/knife-ec-backup/pulls{/number}","milestones_url":"https://api.github.com/repos/chef/knife-ec-backup/milestones{/number}","notifications_url":"https://api.github.com/repos/chef/knife-ec-backup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef/knife-ec-backup/labels{/name}","releases_url":"https://api.github.com/repos/chef/knife-ec-backup/releases{/id}","created_at":"2013-10-02T22:42:20Z","updated_at":"2014-11-28T18:44:05Z","pushed_at":"2015-01-26T16:32:40Z","git_url":"git://github.com/chef/knife-ec-backup.git","ssh_url":"git@github.com:chef/knife-ec-backup.git","clone_url":"https://github.com/chef/knife-ec-backup.git","svn_url":"https://github.com/chef/knife-ec-backup","homepage":"","size":961,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":5,"forks":5,"open_issues":5,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59"},"html":{"href":"https://github.com/chef/knife-ec-backup/pull/59"},"issue":{"href":"https://api.github.com/repos/chef/knife-ec-backup/issues/59"},"comments":{"href":"https://api.github.com/repos/chef/knife-ec-backup/issues/59/comments"},"review_comments":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59/comments"},"review_comment":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/chef/knife-ec-backup/pulls/59/commits"},"statuses":{"href":"https://api.github.com/repos/chef/knife-ec-backup/statuses/14d38fc84348d10fd3fdc967bc13ed9bd139aa30"}}}}