Skip to content

Conversation

@artix75
Copy link
Contributor

@artix75 artix75 commented Mar 1, 2019

This PR adds the new "backup" command to redis-cli's cluster manager.
As its name suggests, it basically saves a backup of the cluster to a local directory.

The backup can be launched with:

redis-cli --cluster backup NODE_IP:NODE_PORT BACKUP_DIRECTORY

where NODE_IP:NODE_PORT is the entry point address of the cluster (as usual).

ie.

redis-cli --cluster backup 127.0.0.1:7000 /tmp/mycluster_backup

The backup will consist of:

  • An .rdb file for each master node of the cluster
  • A JSON file (nodes.json) containing the cluster configuration

The nodes.json file will contain something like this:

[
  {
    "name": "1cb877c71b1c27aa06a65cb987a27ddbf92b09e7",
    "host": "127.0.0.1",
    "port": 7000,
    "replicate": null,
    "slots": [[0,1],[3,5460]],
    "slots_count": 5460,
    "flags": "master",
    "current_epoch": 8
  },
  {
    "name": "20ad4ede36e5ac6a18a3c0efd673c37f34dfc834",
    "host": "127.0.0.1",
    "port": 7002,
    "replicate": null,
    "slots": [[5461,10922]],
    "slots_count": 5462,
    "flags": "master",
    "current_epoch": 3
  },
  {
    "name": "e7a68de2e71595c8fa4c2e84dc889c16bb558c8c",
    "host": "127.0.0.1",
    "port": 7004,
    "replicate": "20ad4ede36e5ac6a18a3c0efd673c37f34dfc834",
    "slots": [],
    "slots_count": 0,
    "flags": "slave",
    "current_epoch": 5
  },
  ...
]

The command will perform an preliminary check on the cluster. If the cluster has some problem,
the backup will be saved anyway, but it will display a warning message and the number of errors found will be saved inside every node in nodes.json (ie. "cluster_errors": 2).

In the next days I'll add more info to nodes.json (ie. migrating/importing slots), and in the near future I'll also implement a "restore" command. Anyway, at the moment, the backup can be manually restored by using the saved rdb files and info taken from the node.json.

artix75 added 3 commits March 1, 2019 17:41
- Prevent cluster backup if cluster has issues and needs to be fixed.
  This behaviour can be overridden by adding the option
  '--cluster-ignore-issues'
Always save the backup, even if there are problems in the cluster.
Just display a warn message and save "cluster_errors" property
inside the json.
@antirez antirez merged commit 56cf413 into redis:unstable Mar 1, 2019
@antirez
Copy link
Contributor

antirez commented Mar 1, 2019

Thanks again @artix75!

JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Apr 10, 2019
Cluster Manager (redis-cli): new "backup" command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants