chef / knife-ec-backup

Backup and restore Chef Infra Server in a repository-compatible format
Apache License 2.0
31 stars 28 forks source link

Knife EC Backup

Build status Gem Version

Umbrella Project: Knife

Project State: Active

Issues Response Time Maximum: 14 days

Pull Request Response Time Maximum: 14 days

Description

knife-ec-backup can backup and restore the data in a Chef Infra Server installation, preserving the data in an intermediate, editable text format. It is similar to the knife download and knife upload commands and uses the same underlying libraries, but also includes workarounds for objects not yet supported by those tools and various Infra Server API deficiencies. The long-run goal is to improve knife download, knife upload and the Chef Infra Server API and deprecate this tool.

Requirements

This knife plugin requires Chef Infra Client 11.8+.

Server Support

This plugin currently supports Chef Infra Server 12+. Support for the beta key rotation features is provided via the --with-keys-sql flag, but users of this feature should note that this may change once the Chef Infra Server supports an API-based export of the key data.

Installation

Chef Infra Server Install (Recommended)

This gem is installed with Chef Infra Server 12 and later and the sub-commands are available with embedded copy of knife, e.g.:

sudo /opt/opscode/bin/knife ec backup ~/chef-server-backup-directory

If you need a newer version of knife-ec-backup than is on the server you wish to back up, you can install it using the embedded gem command.

/opt/opscode/embedded/bin/gem install knife-ec-backup --no-doc

Chef Workstation Install (Unsupported)

On systems other than the Chef Infra Server, installation of this gem is not tested or supported. However, if you attempt to do so you will need the postgresql libraries installed.

For example, on macOS:

brew install libpq
gem install knife-ec-backup -- --with-pg-config=/usr/local/Cellar/libpq/9.2/bin/pg_config

The current location of pg_config can be determined with brew info libpq.

Running tests

$ bundle install
$ bundle exec rspec spec/

If bundle install fails on the pg gem and the note above does not work for you, try:

$ brew install postgres (if not present)
$ ARCHFLAGS="-arch x86_64" gem install pg
$ bundle exec rspec spec/

Build from source

Clone the git repository and run the following from inside:

gem build knife-ec-backup.gemspec
gem install knife-ec-backup*gem

Configuration

Permissions

Note that most users in a Chef Infra Server installation lack the permissions to pull all of the data from all organizations and other users. This plugin REQUIRES THE PIVOTAL KEY AND WEBUI KEY from the Chef Infra Server. It is recommended that you run this from a frontend Chef Infra Server. You can use --user pivotal --key /path/to/pivotal.pem to provide a path to the pivotal key.

Subcommands

Common Options

The following options are supported across all subcommands:

knife ec backup DEST_DIR (options)

Path: If you have Chef Infra Client installed on this server, you may need to invoke this as /opt/opscode/bin/knife ec backup BACKUP_DIRECTORY

Options

Creates a repository of an entire Chef Infra Server

The format of the repository is based on the knife-essentials (knife download) format and looks like this:

users
  <name>.json
user_acls
  <name>.json
organizations
  <orgname>
    acls
      <type>
        <name>.json
    clients
      <name>.json
    containers
      <name>.json
    cookbooks
      <name>-<version>
    data_bags
      <bag name>
        <item name>
    environments
      <name>.json
    groups
      <name>.json
    nodes
      <name>.json
    roles
      <name>.json
    org.json
    members.json
    invitations.json

This compares very closely with the "knife download /" from an OSC server:

clients
  <name>.json
cookbooks
  <name>-<version>
data_bags
  <bag name>
    <item name>
environments
  <name>.json
nodes
  <name>.json
roles
  <name>.json
users
  <name>.json>

knife ec restore DEST_DIR (options)

Restores all data from the specified DEST_DIR to a Chef Infra Server. DEST_DIR should be a backup directory created by knife ec backup

Options

knife ec key export [FILENAME]

Create a json representation of the users table from the Chef Infra Server database. If no argument is given, the name of the backup is key_dump.json.

Please note, most users should use knife ec backup with the --with-user-sql option rather than this command.

knife ec key import [FILENAME]

Import a json representation of the users table from FILENAME to the the Chef Infra Server database. If no argument is given, the filename is assumed to be key_dump.json.

Please note, most users should use knife ec restore with the --with-user-sql option rather than this command.

Known Bugs