Chef Infra Server is backed up with chef-server-ctl backup and restored with chef-server-ctl restore. Chef Automate has its own commands, chef-automate backup create and chef-automate backup restore. This guide adds runnable commands, scheduling, off-host storage, verification steps and fixes for the gist above, whose Hugo shortcodes do not render.
Chef Infra Server Backup and Restore
Chef Automate Backup and Restore
What each tool backs up
Chef Infra Server and Chef Automate store different data and use different backup tools. Pick the method that matches your topology. Tested backups of the wrong component will not save you.
| Deployment | Backup command | What is captured |
|---|---|---|
| Standalone Chef Infra Server | chef-server-ctl backup | Server configuration, PostgreSQL data (orgs, users, nodes, roles, environments, data bags) and Bookshelf cookbook files |
| Chef Backend HA cluster (end of life) | chef-backend-ctl backup on a follower plus chef-server-ctl backup --config-only on a frontend | Cluster data plus frontend configuration |
| Chef Automate (including an embedded Infra Server deployed with Automate) | chef-automate backup create | Automate configuration, service databases and search-engine snapshots |
Note: The search index is not something you restore. After restoring Chef Infra Server, rebuild it with chef-server-ctl reindex --all so that knife search and search in recipes return correct results.
Back up a standalone Chef Infra Server
The gist above shows {{% chef-server/ctl_chef_server_backup_options %}} placeholders where the options should be. These are the options that chef-server-ctl backup --help prints on current releases:
| Option | Purpose |
|---|---|
-y, --yes | Agree that the server can go offline during a tar-based backup, without an interactive prompt. Scripts and cron jobs need this. |
-c, --config-only | Back up only the configuration, not the data. Used with Chef Backend or an external PostgreSQL. |
-t, --timeout SECONDS | Maximum time to wait for each shell command. The default is 600. |
-h, --help | Show usage. |
# Run as root on the Chef Infra Server
sudo chef-server-ctl backup --yes
# The archive is written to /var/opt/chef-backup by default
ls -lh /var/opt/chef-backup/Code language: PHP (php)
Expect a timestamped archive named something like chef-backup-<date-time>.tgz. Chef Infra Clients cannot converge while the server is offline, so run backups in a quiet window. The upstream documentation estimates about 4 to 5 minutes per GB of data on a t3.2xlarge instance. Plan the window from your own data size.
Schedule backups and copy them off the host
A backup that only exists on the server it protects is lost with that server. The script below takes a backup, copies the newest archive to S3 and removes local copies older than seven days. Replace the bucket name, and install and configure the AWS CLI first, ideally with an instance role instead of static keys.
#!/usr/bin/env bash
# /usr/local/sbin/chef-server-backup.sh
set -euo pipefail
BACKUP_DIR=/var/opt/chef-backup
REMOTE=s3://example-chef-backups/infra-server/
chef-server-ctl backup --yes
LATEST=$(ls -1t "$BACKUP_DIR"/chef-backup-* | head -n 1)
aws s3 cp "$LATEST" "$REMOTE"
find "$BACKUP_DIR" -name 'chef-backup-*' -mtime +7 -deleteCode language: PHP (php)
# /etc/cron.d/chef-server-backup (daily at 02:00)
0 2 * * * root /usr/local/sbin/chef-server-backup.sh >> /var/log/chef-server-backup.log 2>&1Code language: PHP (php)
Note: The archive contains the server's private keys and secrets from /etc/opscode. Encrypt the storage, for example with S3 server-side encryption, and limit read access to the people who perform restores.
Restore Chef Infra Server on a new host
- Build a host with the same hostname/FQDN as the original. Clients and
knifeconfigurations point at that name and validate its certificate. - Install the same version of the Chef Infra Server package as the one that created the backup. Restore requires 14.11.36 or later. Upgrade only after the restore succeeds.
- Copy the archive to the new host, for example to
/tmp/chef-backup.tgz, and make sure the disk has room for the expanded data. - Run the restore. Add
--cleanseonly if the target already holds data you intend to wipe. - Rebuild the search index.
- Verify the server, as described in the next section, before you point clients at it.
sudo chef-server-ctl restore /tmp/chef-backup.tgz
# Optional: choose a staging directory with more free space
sudo chef-server-ctl restore /tmp/chef-backup.tgz --staging-dir /data/restore-staging
# Rebuild search
sudo chef-server-ctl reindex --allCode language: PHP (php)
Note: --cleanse deletes all existing data on the target Chef Infra Server. Never run it against a server that is still in production.
Back up and restore Chef Automate
Chef Automate manages its own backups. By default it writes them to /var/opt/chef-automate/backups, and each backup is identified by a timestamp ID such as 20240115020000.
sudo chef-automate backup create # take a backup and print its ID
sudo chef-automate backup list # list available backups
sudo chef-automate backup show <BACKUP_ID>
sudo chef-automate backup delete <BACKUP_ID>
sudo chef-automate backup status # check a running backup or restoreCode language: PHP (php)
To send backups to a dedicated mount or to S3, patch the Automate configuration. Use one of the two blocks below.
# backup.toml - filesystem location
[global.v1.backups.filesystem]
path = "/mnt/automate_backups"
# --- or S3 ---
[global.v1.backups]
location = "s3"
[global.v1.backups.s3.bucket]
name = "example-automate-backups"
base_path = "automate"
endpoint = "https://s3.amazonaws.com"Code language: PHP (php)
sudo chef-automate config patch backup.tomlCode language: CSS (css)
To restore, pass the path or URL of the backup. If the backups are on a filesystem and you restore on a new host, copy the entire backup root directory, not only the timestamped folder. Search-engine snapshot data is stored beside the timestamped folders.
# From the local filesystem
sudo chef-automate backup restore /var/opt/chef-automate/backups/<BACKUP_ID>
# From S3
sudo chef-automate backup restore s3://example-automate-backups/automate/<BACKUP_ID>
# Air-gapped host: also supply the install bundle
sudo chef-automate backup restore --airgap-bundle /path/to/automate.aib /path/to/backups/<BACKUP_ID>Code language: PHP (php)
Run chef-automate backup restore --help on your version to see the credential, endpoint and preflight flags it supports. Afterwards, chef-automate status should show every service as running.
Verify a restore
A backup only counts once you have restored it successfully. Restore to an isolated test host on a regular schedule and run these checks:
sudo chef-server-ctl status # all services should report run:
sudo chef-server-ctl org-list
sudo chef-server-ctl user-list
# From a workstation whose config.rb points at the restored server
knife node list
knife cookbook list
knife search node '*:*' -i
# On a test node
sudo chef-clientCode language: PHP (php)
Compare the node, cookbook and organization counts with the source server. If knife node list shows nodes but knife search returns nothing, run chef-server-ctl reindex --all again. The knife command line reference covers the workstation commands in more detail.
Corrections to the original material
- The embedded gist is copied from Chef's documentation source. Its
{{% ... %}}and{{< note >}}Hugo shortcodes never render, so the actual backup and restore options and syntax are missing. The tables above fill that gap. - The Chef Backend restore example uses
198.52.1000.0, which is not a valid IPv4 address because each octet must be 0 to 255. Use a real address, for examplechef-backend-ctl restore --publish_address 198.51.100.10 /backups/backup.tar.gz. - The secrets file must be copied to
/tmp/chef-backend-secrets.jsonwith a leading slash, nottmp/.... Otherwise the later-s /tmp/chef-backend-secrets.jsonoption will not find it. - The troubleshooting snippet is Ruby, not bash. It also patches a gem path that is hard-coded to one Ruby and one
chef-server-ctlversion and is overwritten on upgrade. The supported fix is to upgrade Chef Infra Server to 14.11.36 or later. - Chef Backend is end of life. New high-availability designs should not be built on it.
- The Chef Automate list in the original ends with an empty bullet, which can be removed.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Backup waits for input in cron and never finishes | --yes not passed | Run chef-server-ctl backup --yes |
| Restore fails with a timeout | Large PostgreSQL or Bookshelf data | Increase the timeout, for example --timeout 3600 |
| Restore fails with "no space left on device" | Default staging area too small | Use --staging-dir on a larger volume |
| Clients report SSL or certificate errors after restore | Different FQDN on the new host | Use the original FQDN, or regenerate certificates and run knife ssl fetch |
| Data is present but search returns nothing | Index not rebuilt | chef-server-ctl reindex --all |
| Automate restore cannot find search data | Only the timestamped folder was copied | Copy the whole backup root directory |
Frequently asked questions
Where does chef-server-ctl backup store its files?
By default it writes a timestamped archive to /var/opt/chef-backup on the Chef Infra Server. Copy it to separate, encrypted storage, because it contains keys and secrets.
Does Chef Infra Server go offline during a backup?
A standalone tar-based backup can take the server offline for its duration, which is why --yes exists to confirm it. Schedule backups for a quiet window when few Chef Infra Client runs are expected.
Can I restore a Chef Infra Server backup to a newer version?
Install the same version that created the backup, restore it, verify it, and then upgrade with the normal upgrade process. This avoids a data restore and a schema migration happening at the same time.
Do I need to back up Chef Infra Server separately if it runs inside Chef Automate?
No. When Infra Server is deployed as part of Chef Automate, chef-automate backup create includes it. Use chef-server-ctl backup only for a standalone Chef Infra Server installation.
Why does knife search return no results after a restore?
The search index is rebuilt, not restored. Run chef-server-ctl reindex --all and check again once it finishes.
Related tutorials
- Chef Tutorials: knife command line reference
- What is Chef and use cases of Chef?
- More Chef tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals