How to backup Autojoin data from Redis in HipChat Server
Purpose
Autojoin data contains the room and 1-1 chat listings for the HipChat clients sidebar. This data is not stored on disk on the server, but instead inside of Redis cache. The following outlines how to backup this specific data from the Redis server running locally inside HipChat Server.
This will not work for HipChat Data Center (since Redis is running externally and requires hostname and authentication arguments to gain access to the Redis CLI).
Backup Autojoin Data from Redis
- Log into the HipChat Server command line interface.
Gain root access:
sudo dont-blame-hipchat
Create a temporary directory to house the lists and switch to that directory.
mkdir /home/admin/autojoin_temp && cd /home/admin/autojoin_temp
Run the following for loop. This will iterate through the Redis cache and pull out each of the user specific autojoin keys, assign a label and save them to disk for each one.
for key in $(redis-cli KEYS "*autoJoin*" | sed 's/^[1-9][0-9]*) //g'); do echo "[$(date +%Y-%m-%dT%H:%M:%S)] Exporting $key"; redis-cli GET $key > ${key}.value; done
Once this is completed, you will see several files labeled 'pref:autoJoin:n.value' in the /home/admin/autojoin_temp folder. The following command will tar those files up into a redis_exports.tgz file:
tar czvf redis_exports.tgz pref\:autoJoin*
Next, we can cleanup the autojoin files that were just added to the redis_exports.tgz archive
rm pref\:autoJoin*
(Optional) Append the date timestamp to the newly created archive file.
mv redis_exports.tgz redis_exports_$(date +%Y-%m-%d-%H-%M-%S).tgz
Restore Autojoin Data from Redis
- While in the HipChat Server command line interface as root, locate the redis_exports_<date>.tgz backup archive.
- Create or navigate to a temp folder that is empty and change to that directory.
Uncompress this archive into this temp directory:
tar xzvf /path/to/redis_exports_<date>.tgz
Run the following command to iterate placing the autojoin data back into Redis:
for file in $(ls pref\:autoJoin*.value); do key=$(echo $file | sed 's/.value//g'); value=$(cat $file); echo "[$(date +%Y-%m-%dT%H:%M:%S)] Import $key from $file"; redis-cli SET $key "$value"; done
After the new keys are imported, delete the pref:autoJoin:n.value files:
rm pref\:autoJoin*
Additional Notes
- This will only backup the autojoin data for users that have an autojoin value in Redis.
- This will not backup user accounts or any other data in the database or in cache.