FAQ - Is it possible to change the set when restoring an Aerospike backup?
In some instances it may be desirable to change the set a backup is restored into from the original set to a new set. The set name is stored in plain text in the backup file, is it therefore possible to change this and restore from that backup changing the set?
It is not possible to change the name of the set to restore into using only
asrestore tools. Although it is present in plain text in the backup file, the set name is contained in the record digest which is a one way hash. To re-compute the digest, the primary key must be stored, and this is not done by default. Thus, replacing the setname in a backup file in order to restore to a different set would require a complex workaround script described below.
The digest is calculated by taking a set name and the key together. Therefore, unless the primary key was also saved into the database, changing/adding a set name will not be possible as it will cause unintended consequences (set name being computed in the digest not matching the set name saved with the record).
The best way to store the key as well as the digest is by setting a SendKey policy on the client: https://www.aerospike.com/apidocs/java/com/aerospike/client/policy/Policy.html#sendKey
Such workaround would require, as described above, the primary_key to be present in the backup file (and therefore, to have been stored, per a non default client policy) and would then recompute the records digests using the new set name.
This is an example of an entry in the backup, which does not contain a set.
+ n default + d EqFBu8DuNLL0DYAFD8uo7g+Med0= + g 1 + t 0 + b 5 - S id 38 TT7c98f6f1-4c5d-11e7-b1fb-00123e35bcdd - I oo 1 - B oos 0 - B sd 20 wAAAAQABAAAABAAAAA== - I sd_dec_size 12
We add a set to the entry itself (to reflect set name for the record) by adding the following line, just after the first 2 lines:
+ s setNameHere
For example, to add a set called ‘exampleSet’, the entry would look like this:
+ n default + d EqFBu8DuNLL0DYAFD8uo7g+Med0= + s exampleSet + g 1 + t 0 + b 5 - S id 38 TT7c98f6f1-4c5d-11e7-b1fb-00123e35bcdd - I oo 1 - B oos 0 - B sd 20 wAAAAQABAAAABAAAAA== - I sd_dec_size 12
Once this is done for all the entries (will have to be scripted), we are tasked with another issue. We will now need to recalculate the record’s digest. For this, a method exists which allows us to calculate the digest, given the key and a set name. The method can be found in this file.
Essentially, the script will need to read the PK entries (from SendKey), and call the computeDigest method for each entry. Once the digest is computed, it should be inserted in place of the current one (line 2: + d …).
It is generally discouraged to change set names on existing data sets with this method, due to high probability of error. If it is required though, the above method will allow for the set name to be changed/added at your own risk.
BACKUP RESTORE CHANGE SET NAME