Last active
June 12, 2024 18:12
-
-
Save keybits/ce86d66cc02dcfe063531945ba8a3f9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euf -o pipefail | |
#### INSTRUCTIONS ######## | |
# Before running this script: | |
# 1. Install the new Algolia CLI: https://www.algolia.com/doc/tools/cli/get-started/overview/ | |
# 2. Install jq: https://stedolan.github.io/jq/download/ | |
# 2. Add your application with `algolia profile add` and follow the prompts | |
# 3. Run `algolia profile list` and copy the name of the application you want to backup | |
# 4. Create an empty directory for this script and the files it will create | |
# 5. Make this script executable `chmod +x backup-algolia-app.sh` | |
# Now run this script with `./backup-algolia-app.sh` | |
########################## | |
# prompt for the application to backup | |
read -p "Enter the application name to backup:`echo $'\n> '`" name | |
# make a directory for the backup | |
mkdir $name | |
# get the indices for the current app | |
algolia indices list -p $name -o json > $name/indices.json | |
# get the index names using jq and add to the INDICES array | |
INDICES=($(jq '.items[].name' $name/indices.json)) | |
#loop through the indices and backup the objects, settings and rules for each index | |
for i in "${INDICES[@]}" | |
do | |
# remove quotes from string | |
i="${i%\"}" | |
i="${i#\"}" | |
# backup each index | |
algolia objects browse $i >$name/objects-$i.json | |
algolia settings get $i > $name/settings-$i.json | |
algolia rules browse $i > $name/rules-$i.json | |
algolia synonyms browse $i > $name/synonyms-$i.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this script currently doesn't back up custom dictionary entries or their settings, so if you have those, please be aware. Adding the ability to back those up is on the roadmap for the Algolia CLI.