Periodic backups of Chef server data are an essential part of managing and maintaining a healthy configuration and to help ensure that important data can be restored, if required.
Note
This section only applies to the Enterprise Chef server, version 11.x.
To configure backups on the backend servers in a high availability configuration, set a cron job in /etc/cron.d/opc_snapshot
similar to the following:
# Add to /etc/cron.d/opc_snapshot, and then remove comment below MAILTO to activate the cron job SHELL=/bin/bash HOME=/opt/opscode/bin PATH=/usr/bin:/usr/sbin:/bin:/opt/opscode/embedded/bin:/opt/opscode/bin [email protected] #17 23 * * * root drbd-backups -g opscode -l drbd > /dev/null 2>&1
A cron job similar to the previous example will mount a new snapshot logical volume named:
/dev/opscode/backup-{+%Y-%m-%d-%H-%M-%S}
where {+%Y-%m-%d-%H-%M-%S}
is a format string for year, month, day, so on.
After the cron job has run successfully, the mount
command will show the new logical volume mounted on the /var/opt/opscode/drbd-backups
mount point. The backup script will create a snapshot logical volume in unused space in the /opscode
volume group. After the snapshot is created, the backup script will attempt to mount the snapshot logical volume, after which the snapshot will stay mounted for 24 hours. Upon the next cron job run, the backup script will attempt to unmount, destroy the snapshot, and then repeat the sequence.
Note
The drbd-backups
script with default settings requires at least 40 GB free space in the /opscode
volume group on the backend servers.
Data stored in the following directories should be backed up periodically:
This data is also essential when any type of backup and restore operation is done for the Chef server.
When backing up Chef server data, be sure that the system is shut down (or otherwise quiet) at the time of the backup. Perform all activities as root unless otherwise directed.
Make a postgres export using the following commands:
export THEDATE=`date '+%Y-%m-%d-%H-%M-%S'` sudo -E -u opscode-pgsql bash /opt/opscode/embedded/bin/pg_dumpall -c | gzip --fast > /tmp/postgresql-dump-$THEDATE.gz Ctrl-d
Synchronize to make sure that all of the data is present on-disk:
sync
Backup the /etc/opscode and /var/opt/opscode directories and include the postgres export file as root
tar cvfzp var-opt-opscode-$THEDATE.tar.gz /etc/opscode /var/opt/opscode /tmp/postgresql-dump-$THEDATE.gz
When restoring Chef server data, the previously backed-up files will be required, along with the Chef server running only the postgresql service. Perform all activities as root unless otherwise directed.
Stop the Chef server:
$ chef-server-ctl stop
Restore the previously backed-up files to the following locations:
/etc/opscode
/var/opt/opscode
by using the following command, which will exclude PostgreSQL files:
tar xvfzp var-opt-opscode-$THEDATE.tar.gz --exclude='var/opt/opscode/drbd/data/postgresql_9.2' -C /
Start the postgresql service:
$ chef-server-ctl start postgresql
Restore the PostgreSQL database:
su - opscode-pgsql gunzip -c postgresql-dump-$THEDATE.gz | /opt/opscode/embedded/bin/psql -U "opscode-pgsql" -d postgresIgnore the following error messages:
ERROR: current user cannot be dropped
ERROR: role "opscode-pgsql" already exists
Reconfigure the Chef server:
$ chef-server-ctl reconfigure
Start the Chef server:
$ chef-server-ctl start
Reconfigure the Chef management console:
$ opscode-manage-ctl reconfigure
Use the following commands to manage backups of Chef server data, and then to restore those backups.
The backup
subcommand is used to back up all Chef server data. This subcommand:
chef-server-ctl reconfigure
prior to running the command/var/opt/chef-backup
directory as a tar.gz file; move this backup to a new location for safe keepingOptions
This subcommand has the following options:
-y
, --yes
Syntax
This subcommand has the following syntax:
$ chef-server-ctl backup
The restore
subcommand is used to restore Chef server data from a backup that was created by the backup
subcommand. This subcommand may also be used to add Chef server data to a newly-installed server. This subcommand:
chef-server-ctl reconfigure
prior to running the commandchef-server-ctl restore
command is available)Options
This subcommand has the following options:
-c
, --cleanse
-d DIRECTORY
, --staging-dir DIRECTORY
Syntax
This subcommand has the following syntax:
$ chef-server-ctl restore PATH_TO_BACKUP (options)
Examples
$ chef-server-ctl restore /path/to/tar/archive.tar.gz
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs-archive.chef.io/release/server_12-8/server_backup_restore.html