This article describes how to manually back up and restore Redis for PCF.
Redis can be manually backed up and restored in PCF. This process involves some steps that are mentioned below one by one:
To identify your Redis for the PCF deployment name, do the following:
Select one of the following procedures depending on the type of service plan you have:
Follow these steps to SSH onto your Operations Manager installation.
Identify the service instance GUID by running cf service SERVICE_INSTANCE_NAME --guid
.
Here, SERVICE_INSTANCE_NAME
is the name chosen when running the cf create service
command.
Using the GUID you identified above, SSH onto your service instance by running bosh2 -d service-instance_GUID ssh
.
Note: The bosh2 commands are only relevant to PCF 1.12 and earlier. As of PCF 2.0, you can start the command with bosh
.
Follow these steps to SSH onto your Operations Manager installation.
Retrieve the deployment name of the Redis for PCF tile.
In order to identify the dedicated node that has the instance you want to back up, use the deployment name you retrieved above in this command:
bosh2 -d REDIS-DEPLOYMENT-NAME vms
The example output lists several dedicated node
instances:
bosh -d cf-redis vms Using environment 'https://100.155.99.99:99999' as client 'ops_manager'
Task 12550. Done Deployment 'cf-redis' Instance Process State AZ IPs VM CID VM Type cf-redis-broker/example-d4444-474c-9a44-e4144cbc4ec4 running europe-west1-b 10.0.0.0 vm-7835sample-44b2-4544-544d-8d4fb21d0bb3 medium dedicated-node/1f444771-69bb-416b-8ded-a4409b3f0e7b running europe-west1-b 10.0.0.0 vm-4d55sampleb-44ac-4efd-44b5-a0d1444bccb0 medium dedicated-node/644b829f-ba43-4cf3-9f44-644caade44ec running europe-west1-b 10.0.0.0 vm-31f1ea1b-444e-4aa5-44fe-db44446044ae medium dedicated-node/c44df62d-38bb-44a5-9d44-8c44414f6e53 running europe-west1-b 10.0.0.0 vm-3d44c1b8-44ae-4e98-4c44-8f6f6ec444ce medium 4 vms Succeeded
If you don’t know which dedicated-node instance to use, follow these steps:
cf env APP-NAME
cf create-service-key SERVICE-INSTANCE-NAME mykey && cf service-key SERVICE-INSTANCE-NAME mykey
bosh2 vms
command. Match this IP to the matching dedicated-node/GUID in the output shown in Step 3.Use that GUID from the previous step and the Redis deployment name to SSH onto the VM:
bosh2 -d REDIS-DEPLOYMENT-NAME ssh dedicated-node/GUID
You can create a snapshot which creates an RDB file locally or you can create a snapshot and send it to the remote backup destination.
To create a snapshot only, run: sudo /var/vcap/jobs/redis-backups/bin/backup --snapshot
. This creates a new RDB file in /var/vcap/store/redis-backup
To create a snapshot and send it to the pre-configured remote backup destination, run sudo /var/vcap/jobs/service-backup/bin/manual-backup
.
You must have enabled and pre-configured this destination in the "Backups" tab of the Redis for PCF settings.
Note: A manual backup of a large dump.rdb
file can take so long that your SSH connection times out. Therefore, when configuring the backup destination, ensure that you have given yourself enough time in the "Backup timeout" field to complete the backup.
You can also restore your backup file to another instance of the Redis for PCF tile. It can be the same or a different plan.
The instance you are restoring to must have the same resource configuration as the instance you backed up.
Ensure that the persistent disk is large enough to handle the temporary files used during the restore process. It should be 3.5x the amount of RAM in the VM.
Create a new instance of the plan that you want to restore to.
Identify the bosh instance which you just created
Bosh scp the backup file into the /tmp directory
For example: bosh -d cf-redis scp ~/Downloads/2017-12-18.rdb dedicated-node/236203b2-1afa-4a57-9a75-218f068f2d6d:/tmp/2017-12-18.rdb
SSH onto the VM which the instance of your plan is located on.
On this VM, create a directory under /var/vcap/store
, for example my-backups
.
Copy the RDB file from the /tmp directory to the directory you created above, or in any directory below it. Substitute this path, not including var/vcap/store
in the next step.
To verify that the RDB file has not been corrupted run:
md5sum PATH-TO-RDB-FILE
For example: md5sum my-backups/2017-12-18.rdb
Compare the value returned in the above step against the contents of the .md5
file that has a similar name to the backup file. The values should be the same.
The .md5
file is located in the same location as the original backup file.
Switch to root user using sudo su
.
Restore to an On-Demand or Dedicated-VM Plan
Run the command:
sudo /var/vcap/jobs/redis-backups/bin/restore --sourceRDB PATH-TO-RDB-FILE
Retrieve the GUID for the instance you want to restore to by running:
cf service SERVICE-INSTANCE-NAME --guid
Use the GUID you found above in this command:
sudo /var/vcap/jobs/redis-backups/bin/restore --sourceRDB PATH-TO-RDB-FILE --sharedVmGuid GUID
If the restore fails partway through, you may need to manually run some commands to get the instance back into a healthy state.
It logs its process along the way and provides helpful messages in case of failure. The logs are at /var/vcap/sys/log/redis-backups/redis-backups.log
.
The sections below list the restore process steps and related messages that appear on your console. If a step fails, resolve the reason that caused it to fail, and then execute the failed step and every subsequent step manually.
You can retrieve the INSTANCE-PASSWORD
through the binding to your service instance:
Note: The above debugging steps require running as a superuser.
StopAll
Run monit stop all
WaitForStop
Wait for monit services to enter the not monitored
state, you can watch this with watch monit summary
DeleteExistingPersistenceFiles
Clean up existing Redis data files:
rm -f /var/vcap/store/redis/appendonly.aof
rm -f /var/vcap/store/redis/dump.rdb
CopyBackupFileWithCorrectPermissions
Restore your Redis backup file to /var/vcap/store/redis/dump.rdb
and correct the owner and permissions with chown vcap:vcap /var/vcap/store/redis/dump.rdb && chmod 660 /var/vcap/store/redis/dump.rdb
SetAppendOnly
Edit the template Redis config file
with vim $(find /var/vcap/data/jobs/ -name redis.conf)` and make the following line changes:
appendonly yes
-> appendonly no
StartAll
Run monit start all
WaitForStart
Wait for monit services to enter the running
state, you can watch this with watch monit summary
RewriteAOF
Run /var/vcap/packages/redis/bin/redis-cli -a INSTANCE-PASSWORD BGREWRITEAOF
RewriteAOF
Run watch "/var/vcap/packages/redis/bin/redis-cli -a INSTANCE-PASSWORD INFO | grep aof_rewrite_in_progress"
until aof_rewrite_in_progress
is 0
StopAll
Run monit stop all
WaitForStop
Wait for monit services to enter the not monitored
state, you can watch this with watch monit summary
ChownToUserAndGroup
Set correct owner on appendonly.aof
by running chown vcap:vcap /var/vcap/store/redis/appendonly.aof
SetAppendOnly
Edit the template Redis config file with vim $(find /var/vcap/data/jobs/ -name redis.conf)
and make the following line changes:
appendonly no
-> appendonly yes
StartAll
Run monit start all
StopAll
Run monit stop all
WaitForStop
Wait for monit services to enter the not monitored
state, you can watch this with watch monit summary
SetConfigCommand
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and comment out the line:
rename-command CONFIG "configalias"
-> #rename-command CONFIG "configalias"
SetRewriteCommand
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and comment out the line:
rename-command BGREWRITEAOF ""
-> #rename-command BGREWRITEAOF ""
DeleteExistingPersistenceFiles
Clean up existing Redis data files if they exist:
rm -f /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/db/appendonly.aof
rm -f /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/db/dump.rdb
CopyBackupFileWithCorrectPermissions
Restore your Redis backup file to /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/db/dump.rdb
and correct the owner and permissions with chown vcap:vcap /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/db/dump.rdb && chmod 660 /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/db/dump.rdb
SetAppendOnly
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and make the following line changes:
appendonly yes
-> appendonly no
StartAll
Run monit start all
WaitForStart
Wait for monit services to enter the running
state, you can watch this with watch monit summary
RewriteAOF
Run /var/vcap/packages/redis/bin/redis-cli -a INSTANCE-PASSWORD BGREWRITEAOF
RewriteAOF
Run watch "/var/vcap/packages/redis/bin/redis-cli -a INSTANCE-PASSWORD INFO | grep aof_rewrite_in_progress"
until aof_rewrite_in_progress
is 0
StopAll
Run monit stop all
WaitForStop
Wait for monit services to enter the not monitored
state, you can watch this with watch monit summary
ChownToUserAndGroup
Set correct owner on appendonly.aof
by running chown vcap:vcap /var/vcap/store/redis/appendonly.aof
SetAppendOnly
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and make the following line changes:
appendonly no
-> appendonly yes
SetConfigCommand
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and uncomment the line: #rename-command CONFIG "configalias"
-> rename-command CONFIG "configalias"
SetRewriteCommand
Edit the template Redis config file with vim /var/vcap/store/cf-redis-broker/redis-data/INSTANCE-GUID/redis.conf
and uncomment the line: #rename-command BGREWRITEAOF ""
-> rename-command BGREWRITEAOF ""
StartAll
Run monit start all
You can choose to restore the RDB file to any Redis instance outside of PCF.
For information on how Redis handles RDB files, see Redis Persistence.
In the event of a recovery of PCF, it is possible to recover bound Redis instances to healthy states that are in sync with PCF. There are a few requirements for fully recovering a previous instance state, depending on your plan.
A backup Redis RDB dump file
A backed up /var/vcap/store/cf-redis-broker/redis-data
directory from the service broker node. You do not need to back up *.aof
or *.rdb
files from subdirectories if you have backups configured.
A backup Redis RDB dump file
A backed up /var/vcap/store/redis/statefile.json
from the service broker node
Note: The procedures below assume that a recovery of service information and service keys assigned to instances are restored with a restore of PCF.
bosh2 ssh
into the service broker node of your Redis deployment.monit stop all && pkill redis-server
.not monitored
state. You can watch this with watch monit summary
.redis-server
by running ps aux | grep redis-server
.redis-data
directory into /var/vcap/store/cf-redis-broker
.bosh2 ssh
into the service broker node of your Redis deployment.
Run monit stop all
Wait for monit services to enter the not monitored
state, you can watch this with watch monit summary
Copy the backed up /var/vcap/store/cf-redis-broker/statefile.json
and ensure ownership and permissions are correct with
chown vcap:vcap /var/vcap/store/cf-redis-broker/statefile.json && chmod 660 /var/vcap/store/cf-redis-broker/statefile.json
Follow the instructions in Restore a Redis for PCF Instance from a Backup for your plan, to restore your backed up Redis data.
Your Redis instance is now recovered.
If your previous on-demand service-instance deployment does not exist: