├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── dependabot.yml ├── release-draft-template.yml └── workflows │ └── release-drafter.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets └── version_update.gif └── scripts └── update_meilisearch_version.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | 10 | # 4 space indentation 11 | [*.{py,java,r,R}] 12 | indent_style = space 13 | indent_size = 4 14 | 15 | # 2 space indentation 16 | [*.{js,json,y{a,}ml,html,cwl}] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.{md,Rmd,rst}] 21 | trim_trailing_whitespace = false 22 | indent_style = space 23 | indent_size = 2 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 🐞 3 | about: Create a report to help us improve. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | 10 | 11 | **Description** 12 | Description of what the bug is about. 13 | 14 | **Expected behavior** 15 | What you expected to happen. 16 | 17 | **Current behavior** 18 | What happened. 19 | 20 | **Screenshots or Logs** 21 | If applicable, add screenshots or logs to help explain your problem. 22 | 23 | **Environment (please complete the following information):** 24 | - OS and version: [e.g. Debian 9] 25 | - Browser: [e.g. Chrome version 90.0] 26 | - Meilisearch version: [e.g. v.0.20.0] 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Support questions & other 4 | url: https://discord.meilisearch.com/ 5 | about: Support is not handled here but on our Discord 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request & Enhancement 💡 3 | about: Suggest a new idea for the project. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | 10 | 11 | **Description** 12 | Brief explanation of the feature. 13 | 14 | **Basic example** 15 | If the proposal involves something new or a change, include a basic example. How would you use the feature? In which context? 16 | 17 | **Other** 18 | Any other things you want to add. 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "monthly" 7 | labels: 8 | - 'skip-changelog' 9 | - 'dependencies' 10 | rebase-strategy: disabled 11 | -------------------------------------------------------------------------------- /.github/release-draft-template.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$RESOLVED_VERSION 🦜' 2 | tag-template: 'v$RESOLVED_VERSION' 3 | exclude-labels: 4 | - 'skip-changelog' 5 | version-resolver: 6 | minor: 7 | labels: 8 | - 'breaking-change' 9 | default: patch 10 | categories: 11 | - title: 'Breaking changes ⚠️' 12 | label: 'breaking-change' 13 | template: | 14 | ## Changes 15 | 16 | $CHANGES 17 | 18 | Thanks again to $CONTRIBUTORS! 🎉 19 | no-changes-template: 'Changes are coming soon 😎' 20 | sort-direction: 'ascending' 21 | replacers: 22 | - search: '/(?:and )?@dependabot-preview(?:\[bot\])?,?/g' 23 | replace: '' 24 | - search: '/(?:and )?@dependabot(?:\[bot\])?,?/g' 25 | replace: '' 26 | - search: '/(?:and )?@bors(?:\[bot\])?,?/g' 27 | replace: '' 28 | - search: '/(?:and )?@meili-bot,?/g' 29 | replace: '' 30 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | update_release_draft: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: release-drafter/release-drafter@v5 13 | with: 14 | config-name: release-draft-template.yml 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.RELEASE_DRAFTER_TOKEN }} 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | First of all, thank you for contributing to Meilisearch! The goal of this document is to provide everything you need to know in order to contribute to Meilisearch and its different integrations. 4 | 5 | - [Assumptions](#assumptions) 6 | - [How to Contribute](#how-to-contribute) 7 | - [Git Guidelines](#git-guidelines) 8 | - [Release Process (for internal team only)](#release-process-for-internal-team-only) 9 | 10 | ## Assumptions 11 | 12 | 1. **You're familiar with [GitHub](https://github.com) and the [Pull Request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)(PR) workflow.** 13 | 2. **You've read the Meilisearch [documentation](https://www.meilisearch.com/docs) and the [README](/README.md).** 14 | 3. **You know about the [Meilisearch community](https://discord.com/invite/meilisearch). Please use this for help.** 15 | 16 | ## How to Contribute 17 | 18 | 1. Make sure that the contribution you want to make is explained or detailed in a GitHub issue! Find an [existing issue](https://github.com/meilisearch/meilisearch-migration/issues/) or [open a new one](https://github.com/meilisearch/meilisearch-migration/issues/new). 19 | 2. Once done, [fork the meilisearch-migration repository](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) in your own GitHub account. Ask a maintainer if you want your issue to be checked before making a PR. 20 | 3. [Create a new Git branch](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-and-deleting-branches-within-your-repository). 21 | 4. Make the changes on your branch. 22 | 5. [Submit the branch as a PR](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) pointing to the `main` branch of the main meilisearch-migration repository. A maintainer should comment and/or review your Pull Request within a few days. Although depending on the circumstances, it may take longer.
23 | We do not enforce a naming convention for the PRs, but **please use something descriptive of your changes**, having in mind that the title of your PR will be automatically added to the next [release changelog](https://github.com/meilisearch/meilisearch-migration/releases/). 24 | 25 | ## Git Guidelines 26 | 27 | ### Git Branches 28 | 29 | All changes must be made in a branch and submitted as PR. 30 | We do not enforce any branch naming style, but please use something descriptive of your changes. 31 | 32 | ### Git Commits 33 | 34 | As minimal requirements, your commit message should: 35 | 36 | - be capitalized 37 | - not finish by a dot or any other punctuation character (!,?) 38 | - start with a verb so that we can read your commit message this way: "This commit will ...", where "..." is the commit message. 39 | e.g.: "Fix the home page button" or "Add more tests for create_index method" 40 | 41 | We don't follow any other convention, but if you want to use one, we recommend [this one](https://chris.beams.io/posts/git-commit/). 42 | 43 | ### GitHub Pull Requests 44 | 45 | Some notes on GitHub PRs: 46 | 47 | - [Convert your PR as a draft](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/changing-the-stage-of-a-pull-request) if your changes are a work in progress: no one will review it until you pass your PR as ready for review.
48 | The draft PR can be very useful if you want to show that you are working on something and make your work visible. 49 | - The branch related to the PR must be **up-to-date with `main`** before merging. If it's not, you have to rebase your branch. Check out this [quick tutorial](https://gist.github.com/curquiza/5f7ce615f85331f083cd467fc4e19398) to successfully apply the rebase from a forked repository. 50 | - All PRs must be reviewed and approved by at least one maintainer. 51 | - The PR title should be accurate and descriptive of the changes. 52 | 53 | ## Release Process (for the internal team only) 54 | 55 | Meilisearch tools follow the [Semantic Versioning Convention](https://semver.org/). 56 | 57 | ### Automated Changelogs 58 | 59 | This project integrates a tool to create automated changelogs.
60 | _[Read more about this](https://github.com/meilisearch/integration-guides/blob/main/guides/release-drafter.md)._ 61 | 62 | ### How to Publish the Release 63 | 64 | ⚠️ Before doing anything, make sure you got through the guide about [Releasing an Integration](https://github.com/meilisearch/integration-guides/blob/main/guides/integration-release.md). 65 | 66 | You can publish the current draft release via the [GitHub interface](https://github.com/meilisearch/XXX/releases): on this page, click on `Edit` (related to the draft release) > update the description (be sure you apply [these recommendations](https://github.com/meilisearch/integration-guides/blob/main/guides/integration-release.md#writting-the-release-description)) > when you are ready, click on `Publish release`. 67 | 68 |
69 | 70 | Thank you again for reading this through. We can not wait to begin to work with you if you make your way through this contributing guide ❤️ 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2025 Meili SAS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Meilisearch Version Update Script 3 |

4 | 5 |

Meilisearch Version Migration Script

6 | 7 |

8 | Meilisearch | 9 | Documentation | 10 | Discord | 11 | Roadmap | 12 | Website | 13 | FAQ 14 |

15 | 16 |

17 | License 18 |

19 | 20 | --- 21 | 22 | 🚨 IMPORTANT NOTICE: Reduced Maintenance & Support 🚨 23 | 24 | *Dear Community,* 25 | 26 | *We'd like to share some updates regarding the future maintenance of this repository:* 27 | 28 | *Our team is small, and our availability will be reduced in the upcoming times. As such, response times might be slower, and we will not be accepting enhancements for this repository moving forward.* 29 | 30 | *If you're looking for reliable alternatives, consider using [Cloud Service](https://www.meilisearch.com/pricing?utm_campaign=oss&utm_source=integration&utm_medium=meilisearch-migration). It offers a robust solution for those seeking an alternative to this repository.* 31 | 32 | *Seeking immediate support? Please join us on [our Discord channel](https://discord.meilisearch.com).* 33 | 34 | --- 35 | 36 |

🦜 Meilisearch script to update version and migrate data 🦜

37 | 38 | **Meilisearch Version Migration Script** is a script that migrates your Meilisearch from a version, v.0.22.0 or higher, to a newer version without losing data nor settings. 39 | 40 | **Meilisearch** is an open-source search engine. [Discover what Meilisearch is!](https://github.com/meilisearch/meilisearch) 41 | 42 | ## Table of Contents 43 | 44 | - [☝️ Requirements](#-requirements) 45 | - [🚗 Usage](#-usage) 46 | - [🎉 Features](#-features) 47 | - [💔 Incompatible Versions](#-version-incompatibilities) 48 | - [📖 Documentation](#-documentation) 49 | - [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch) 50 | - [⚙️ Development Workflow and Contributing](#️-development-workflow-and-contributing) 51 | 52 | ## ☝️ Requirements 53 | 54 | ### 1. Systemctl 55 | 56 | Currently the script only works in an environment in which Meilisearch is running as a `systemctl` service. 57 | 58 | ### 2. Correct data.ms path 59 | 60 | The Meilisearch's `data.ms` must be stored at the following path: `/var/lib/meilisearch/data.ms`.
61 | To ensure this is the case, Meilisearch should have started with the following flags: `--db-path /var/lib/meilisearch/data.ms` 62 | 63 | You can check the information by looking at the file located here `cat /etc/systemd/system/meilisearch.service`.
64 | You should find a line with the specific command used. 65 | 66 | ```bash 67 | ExecStart=/usr/bin/meilisearch --db-path /var/lib/meilisearch/data.ms --env production 68 | ``` 69 | 70 | By default all Meilisearch instances created using one of our cloud providers are storing `data.ms` in this directory. 71 | 72 | ### 3. A Running Meilisearch instance 73 | 74 | A Meilisearch instance with a version greater than v0.21 should be running before launching the script. This can be checked using the following command: 75 | 76 | ```bash 77 | systemctl status meilisearch 78 | ``` 79 | 80 | If you don't have a running Meilisearch instance, you can create one using one of our Cloud Providers: 81 | 82 | | Cloud Provider | Project | 83 | | -------------- | :----------------------------------------------------------------------------------- | 84 | | DigitalOcean | [meilisearch-digitalocean](https://github.com/meilisearch/meilisearch-digitalocean/) | 85 | | AWS | [meilisearch-aws](https://github.com/meilisearch/meilisearch-aws/) | 86 | | GCP | [meilisearch-gcp](https://github.com/meilisearch/meilisearch-gcp/) | 87 | 88 |
89 | 90 | Alternatively, by [downloading and running Meilisearch](https://www.meilisearch.com/docs/learn/getting_started/installation) on your own server and start it as a [systemctl service](https://www.freedesktop.org/software/systemd/man/systemctl.html). 91 | 92 | ## 🚗 Usage 93 | 94 | ⚠️ In case of failure during the execution of the script and for security purposes, we strongly recommend [creating manually your own dump](https://www.meilisearch.com/docs/learn/advanced/dumps#creating-a-dump). After creating a dump, the file is located at `/dumps` at the root of the server. 95 | 96 | Download the script on your Meilisearch server: 97 | 98 | ```bash 99 | curl https://raw.githubusercontent.com/meilisearch/meilisearch-migration/main/scripts/update_meilisearch_version.sh --output migration.sh --location 100 | ``` 101 | 102 | To launch the script you should open the server using SSH and run the following command: 103 | 104 | ```bash 105 | bash migration.sh meilisearch_version 106 | ``` 107 | 108 | - `meilisearch_version`: the Meilisearch version formatted like this: `vX.X.X` 109 | 110 | **Note** 111 | 112 | If you want to run the script from an AWS instance and you are logged in as `admin`, you probably have to use this command instead: 113 | ```bash 114 | sudo -E bash migration.sh meilisearch_version 115 | ``` 116 | 117 | If you want to run the script from a GCP VM instance and you are logged in as a user, you probably have to set the $MEILISEARCH_MASTER_KEY like: 118 | ```bash 119 | export MEILISEARCH_MASTER_KEY=YOUR_API_KEY 120 | ``` 121 | Then run the command line as sudo: 122 | ```bash 123 | sudo bash migration.sh meilisearch_version 124 | ``` 125 | 126 | ### Example: 127 | 128 | An official release: 129 | 130 | ```bash 131 | bash migration.sh v0.24.0 132 | ``` 133 | 134 | A release candidate: 135 | 136 | ```bash 137 | bash migration.sh v0.24.0rc1 138 | ``` 139 | 140 | ![](../../assets/version_update.gif) 141 | 142 | ## 🎉 Features 143 | 144 | - [Automatic Dumps](#automatic-dumps) export and import in case of version incompatibility. 145 | - [Rollback](#rollback-in-case-of-failure) in case of failure. 146 | 147 | ### Automatic Dumps 148 | 149 | The script is made to migrate the data properly in case the required version is not compatible with the current version. 150 | 151 | It is done by doing the following: 152 | 153 | - Create a dump 154 | - Stop Meilisearch service 155 | - Download and update Meilisearch 156 | - Start Meilisearch 157 | - If the start fails because versions are not compatible: 158 | - Delete current `data.ms` 159 | - Import the previously created dump 160 | - Restart Meilisearch 161 | - Remove generated dump file. 162 | 163 | ### Rollback in case of failure 164 | 165 | If something goes wrong during the version update process a rollback occurs: 166 | 167 | - The script rolls back to the previous Meilisearch version by using the previous cached Meilisearch binary. 168 | - The previous `data.ms` is used and replaces the new one to ensure Meilisearch works exactly as before the script was used. 169 | - Meilisearch is started again. 170 | 171 | Example: 172 | Your current version is `v0.23.0` you want to update Meilisearch to `v0.24.0`. Thus inside your server you import and launch the script 173 | 174 | ``` 175 | bash migration.sh v0.24.0 176 | ``` 177 | 178 | The migration fails for whatever reason. The script uses the cached `v0.23.0` binary and the cached `data.ms` of the previous version to rollback to its original state. 179 | 180 | ## 💔 Version incompatibilities 181 | 182 | Versions that are lower than the v0.22.0 can not be migrated. 183 | 184 | It may also happen that versions are incompatible with each other in some specific cases. The breaking changes are described in the CHANGELOG of the release. 185 | 186 | In this case, an error will be thrown by Meilisearch and the script will roll back to the version of Meilisearch before launching the script. 187 | 188 | In order to do the update to the next version, you'll have to manually: 189 | 190 | - Export your data without using the dumps, for example by browsing your documents using [this route](https://www.meilisearch.com/docs/reference/api/documents#get-documents). 191 | - Download and launch the binary corresponding to the new version of Meilisearch. 192 | - Re-index your data and the new settings in the new Meilisearch instance. 193 | 194 | ## 📖 Documentation 195 | 196 | See our [Documentation](https://www.meilisearch.com/docs/learn/getting_started/quick_start) or our [API References](https://www.meilisearch.com/docs/reference/api/overview). 197 | 198 | ## 🤖 Compatibility with Meilisearch 199 | 200 | This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-migration/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info. 201 | 202 | ## ⚙️ Development Workflow and Contributing 203 | 204 | Any new contribution is more than welcome in this project! 205 | 206 | If you want to know more about the development workflow or want to contribute, please visit our [contributing guidelines](/CONTRIBUTING.md) for detailed instructions! 207 | 208 |
209 | 210 | **Meilisearch** provides and maintains many **SDKs and Integration tools** like this one. We want to provide everyone with an **amazing search experience for any kind of project**. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the [integration-guides](https://github.com/meilisearch/integration-guides) repository. 211 | -------------------------------------------------------------------------------- /assets/version_update.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meilisearch/meilisearch-migration/16027aff41137f0644a3c385df8f74e219776264/assets/version_update.gif -------------------------------------------------------------------------------- /scripts/update_meilisearch_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Constants 4 | 5 | RED="\033[0;31m" 6 | BRED="\033[1;31m" 7 | BGREEN="\033[1;32m" 8 | BYELLOW="\033[1;33m" 9 | BBLUE="\033[1;34m" 10 | BPINK="\033[1;35m" 11 | WHITE="\033[0m" 12 | NC="\033[0m" 13 | ERROR_LABEL="${BRED}error: ${NC}" 14 | SUCCESS_LABEL="${BGREEN}success: ${NC}" 15 | PENDING_LABEL="${BYELLOW}pending: ${NC}" 16 | INFO_LABEL="${BBLUE}info: ${NC}" 17 | WARNING_LABEL="${BYELLOW}warning: ${NC}" 18 | 19 | ## Utils Functions 20 | 21 | # Rollback to previous Meilisearch version in case something went wrong 22 | 23 | previous_version_rollback() { 24 | 25 | echo -e "${ERROR_LABEL}Meilisearch update to $meilisearch_version failed." >&2 26 | echo -e "${INFO_LABEL}Rollbacking to previous version ${BPINK}$current_meilisearch_version${NC}." >&2 27 | echo -e "${INFO_LABEL}Recovering..." >&2 28 | mv /tmp/meilisearch /usr/bin/meilisearch 29 | echo -e "${SUCCESS_LABEL}Recover previous data.ms." >&2 30 | mv /tmp/data.ms /var/lib/meilisearch/data.ms 31 | echo -e "${INFO_LABEL}Restarting Meilisearch." >&2 32 | systemctl restart meilisearch 33 | systemctl_status exit 34 | echo -e "${SUCCESS_LABEL}Previous Meilisearch version ${BPINK}$current_meilisearch_version${NC} restarted correctly with its data recovered." >&2 35 | delete_temporary_files 36 | echo -e "${WARNING_LABEL}Update Meilisearch from ${BPINK}$current_meilisearch_version${NC} to ${BPINK}$meilisearch_version${NC} failed. Rollback to previous version successfull." >&2 37 | echo -e "${BGREEN}Meilisearch service up and running in version ${NC} ${BPINK}$meilisearch_version${NC}." 38 | exit 39 | } 40 | 41 | # Check if Meilisearch systemctl process is Active 42 | systemctl_status() { 43 | systemctl status meilisearch | grep -E 'Active: active \(running\)' -q 44 | grep_status_code=$? 45 | callback_1=$1 46 | callback_2=$2 47 | if [ $grep_status_code -ne 0 ]; then 48 | echo -e "${ERROR_LABEL}Meilisearch Service is not Running. Please start Meilisearch." >&2 49 | if [ ! -z "$callback_1" ]; then 50 | $callback_1 51 | fi 52 | 53 | if [ ! -z "$callback_2" ]; then 54 | $callback_2 55 | fi 56 | fi 57 | } 58 | 59 | # Delete temporary files 60 | delete_temporary_files() { 61 | echo -e "${INFO_LABEL}Cleaning temporary files..." 62 | if [ -f "meilisearch" ]; then 63 | rm meilisearch 64 | echo -e "${SUCCESS_LABEL}Delete temporary meilisearch binary." 65 | fi 66 | 67 | if [ -f "logs" ]; then 68 | rm logs 69 | echo -e "${SUCCESS_LABEL}Delete temporary logs file." 70 | fi 71 | 72 | local dump_file="/var/opt/meilisearch/dumps/$dump_id.dump" 73 | if [ -f $dump_file ]; then 74 | rm "$dump_file" 75 | echo -e "${SUCCESS_LABEL}Delete temporary dump file." 76 | fi 77 | 78 | } 79 | 80 | # Check if Meilisearch arguments are provided 81 | check_args() { 82 | if [ $1 -eq 0 ]; then 83 | echo -e "${ERROR_LABEL}$2" 84 | exit 85 | fi 86 | } 87 | 88 | # Check if latest command exit status is not an error 89 | check_last_exit_status() { 90 | status=$1 91 | message=$2 92 | callback_1=$3 93 | callback_2=$4 94 | 95 | if [ $status -ne 0 ]; then 96 | echo -e "${ERROR_LABEL}$message." 97 | if [ ! -z "$callback_1" ]; then 98 | ($callback_1) 99 | fi 100 | if [ ! -z "$callback_2" ]; then 101 | ($callback_2) 102 | fi 103 | exit 104 | fi 105 | } 106 | 107 | # Check if the API key is defined is the environment variable 108 | check_api_key() { 109 | if [ -z $MEILISEARCH_MASTER_KEY ]; then 110 | echo -e "${WARNING_LABEL}MEILISEARCH_MASTER_KEY is not available in the environment variables. If you have an API key, set it with the following command 'export MEILISEARCH_MASTER_KEY=YOUR_API_KEY'" 111 | fi 112 | } 113 | 114 | ## Main Script 115 | 116 | # 117 | # Current Running Meilisearch 118 | # 119 | 120 | # Confirm that the API key is defined in the env variables. 121 | check_api_key 122 | 123 | echo -e "${SUCCESS_LABEL}Starting version update of Meilisearch." 124 | 125 | # Check if Meilisearch Service is running 126 | systemctl_status exit 127 | 128 | # Check if version argument was provided on script launch 129 | check_args $# "Meilisearch version not provided as arg.\nUsage: sh update_meilisearch_version.sh [vX.X.X]" 130 | 131 | # Version to update Meilisearch to. 132 | meilisearch_version=$1 133 | 134 | echo -e "${SUCCESS_LABEL}Requested Meilisearch version: ${BPINK}$meilisearch_version${NC}." 135 | 136 | # Current Meilisearch version 137 | # FIXME: Should work without master key provided see issue #44 138 | current_meilisearch_version=$( 139 | curl -X GET 'http://localhost:7700/version' --header "Authorization: Bearer $MEILISEARCH_MASTER_KEY" -s --show-error | 140 | cut -d '"' -f 12 141 | ) 142 | 143 | # Check if curl version request is successfull. 144 | check_last_exit_status $? "Version request 'GET /version' request failed." 145 | echo -e "${SUCCESS_LABEL}Current running Meilisearch version: ${BPINK}$current_meilisearch_version${NC}." 146 | 147 | # 148 | # Back Up Dump 149 | # 150 | 151 | # Create dump for migration in case of incompatible versions 152 | echo -e "${INFO_LABEL}Creation of a dump in case new version does not have compatibility with the current Meilisearch." 153 | dump_return=$(curl -X POST 'http://localhost:7700/dumps' --header "Authorization: Bearer $MEILISEARCH_MASTER_KEY" --show-error -s) 154 | 155 | # Check if curl request was successfull. 156 | check_last_exit_status $? "Dump creation 'POST /dumps' request failed." 157 | 158 | if echo $current_meilisearch_version | grep -E "^[0].2[01234567]{1}.[0-9]+.*" -q; then 159 | # Get the dump id 160 | dump_id=$(echo $dump_return | cut -d '"' -f 4) 161 | echo -e "${INFO_LABEL}Creating dump id with id: $dump_id." 162 | 163 | # Wait for Dump to be created 164 | while true 165 | do 166 | curl -X GET "http://localhost:7700/dumps/$dump_id/status" \ 167 | --header "Authorization: Bearer $MEILISEARCH_MASTER_KEY" --show-error -s -i > curl_dump_creation_response 168 | cat curl_dump_creation_response | grep "200 OK" -q 169 | check_last_exit_status $? "Request to /dumps/$dump_id/status failed" delete_temporary_files 170 | if cat curl_dump_creation_response | grep '"status":"done"' -q; then 171 | rm curl_dump_creation_response 172 | break 173 | elif cat curl_dump_creation_response | grep '"status":"failed"' -q; then 174 | rm curl_dump_creation_response 175 | delete_temporary_files 176 | echo -e "${ERROR_LABEL}Meilisearch could not create the dump:\n ${response}" >&2 177 | exit 178 | fi 179 | echo -e "${PENDING_LABEL}Meilisearch is still creating the dump: $dump_id." 180 | sleep 2 181 | done 182 | else 183 | # Get the task uid 184 | task_uid=$(echo $dump_return | grep -o -E "\"taskUid\":[0-9]+" | awk -F\: '{print $2}') 185 | echo -e "${INFO_LABEL}Creating dump with task uid: $task_uid." 186 | 187 | while true 188 | do 189 | curl -X GET "http://localhost:7700/tasks/$task_uid" \ 190 | --header "Authorization: Bearer $MEILISEARCH_MASTER_KEY" --show-error -s -i > curl_dump_creation_response 191 | cat curl_dump_creation_response | grep "200 OK" -q 192 | check_last_exit_status $? "Request to /tasks/$task_uid failed" 193 | if cat curl_dump_creation_response | grep '"status":"succeeded"' -q; then # | awk -F\: '{print $2}' 194 | dump_id=$(cat curl_dump_creation_response | grep -o -E "\"dumpUid\":\"(.{8}-.{9})\"" | awk -F\: '{print $2}' | tr -d \") 195 | echo $dump_id 196 | rm curl_dump_creation_response 197 | break 198 | elif cat curl_dump_creation_response | grep '"status":"failed"' -q; then 199 | rm curl_dump_creation_response 200 | delete_temporary_files 201 | echo -e "${ERROR_LABEL} Failed to create the dump." 202 | exit 203 | fi 204 | echo -e "${PENDING_LABEL}Meilisearch is still creating the dump with task uid: $task_uid." 205 | sleep 2 206 | done 207 | fi 208 | 209 | echo -e "${SUCCESS_LABEL}Meilisearch finished creating the dump: $dump_id." 210 | 211 | # 212 | # New MeiliSsarch 213 | # 214 | 215 | # Download Meilisearch of the right version 216 | echo -e "${INFO_LABEL}Downloading Meilisearch version ${BPINK}$meilisearch_version${NC}." 217 | response=$(curl "https://github.com/meilisearch/meilisearch/releases/download/$meilisearch_version/meilisearch-linux-amd64" --output meilisearch --location -s --show-error) 218 | 219 | check_last_exit_status $? \ 220 | "Request to download Meilisearch $meilisearch_version release failed." \ 221 | delete_temporary_files 222 | 223 | # Give read and write access to meilisearch binary 224 | chmod +x meilisearch 225 | 226 | # Check if Meilisearch binary is not corrupted 227 | if file meilisearch | grep "ELF 64-bit LSB" -q; then 228 | echo -e "${SUCCESS_LABEL}Successfully downloaded Meilisearch version $meilisearch_version." 229 | else 230 | echo -e "${ERROR_LABEL}Meilisearch binary is corrupted.\n\ 231 | It may be due to: \n\ 232 | - Invalid version syntax. Provided: $meilisearch_version, expected: vX.X.X. ex: v0.22.0 \n\ 233 | - Rate limiting from GitHub." >&2 234 | delete_temporary_files 235 | exit 236 | fi 237 | 238 | echo -e "${INFO_LABEL}Stopping Meilisearch Service to update the version." 239 | ## Stop meilisearch running 240 | systemctl stop meilisearch # stop the service to update the version 241 | 242 | ## Move the binary of the current Meilisearch version to the temp folder 243 | echo -e "${INFO_LABEL}Keep a temporary copy of previous Meilisearch." 244 | mv /usr/bin/meilisearch /tmp 245 | 246 | # Keep cache of previous data.ms in case of failure 247 | cp -r /var/lib/meilisearch/data.ms /tmp/ 248 | echo -e "${INFO_LABEL}Keep a temporary copy of previous data.ms." 249 | 250 | # Remove data.ms 251 | rm -rf /var/lib/meilisearch/data.ms 252 | echo -e "${INFO_LABEL}Delete current Meilisearch's data.ms" 253 | 254 | ## Move new Meilisearch binary to the systemctl directory containing the binary 255 | echo -e "${INFO_LABEL}Update Meilisearch version." 256 | cp meilisearch /usr/bin/meilisearch 257 | 258 | # Run Meilisearch 259 | # TODO: `import-dump` may change name for v1, it should be added in the integration-guide issue 260 | # https://github.com/meilisearch/meilisearch/issues/3132 261 | ./meilisearch --db-path /var/lib/meilisearch/data.ms --env production --import-dump "/var/opt/meilisearch/dumps/$dump_id.dump" --master-key $MEILISEARCH_MASTER_KEY 2>logs & 262 | echo -e "${INFO_LABEL}Run local $meilisearch_version binary importing the dump and creating the new data.ms." 263 | 264 | sleep 2 265 | 266 | # Needed conditions due to bug in Meilisearch #1701 267 | if cat logs | grep "Error: No such file or directory (os error 2)" -q; then 268 | # If dump was empty no import is needed 269 | echo -e "${SUCCESS_LABEL}Empty database! Importing of no data done." 270 | else 271 | echo -e "${INFO_LABEL}Check if local $meilisearch_version started correctly." 272 | # Check if local meilisearch started correctly `./meilisearch ..` 273 | if ps | grep "meilisearch" -q; then 274 | echo -e "${SUCCESS_LABEL}Meilisearch started successfully and is importing the dump." 275 | else 276 | echo -e "${ERROR_LABEL}Meilisearch could not start: \n ${BRED}$(cat logs)${NC}." >&2 277 | # In case of failed start rollback to initial version 278 | previous_version_rollback 279 | fi 280 | 281 | ## Wait for pending dump indexation 282 | while true 283 | do 284 | curl -X GET 'http://localhost:7700/health' \ 285 | --header "Authorization: Bearer $MEILISEARCH_MASTER_KEY" --show-error -s -i > curl_dump_index_response 286 | cat curl_dump_index_response | grep "200 OK" -q 287 | check_last_exit_status $? "Request to /health failed" 288 | if cat curl_dump_index_response | grep '"status":"available"' -q; then 289 | rm curl_dump_index_response 290 | break 291 | else 292 | rm curl_dump_index_response 293 | echo "${ERROR_LABEL} Failed to index the dump" 294 | exit 295 | fi 296 | sleep 2 297 | done 298 | echo -e "${SUCCESS_LABEL}Meilisearch is done indexing the dump." 299 | 300 | # Kill local Meilisearch process 301 | echo -e "${INFO_LABEL}Kill local Meilisearch process." 302 | pkill meilisearch 303 | fi 304 | 305 | regex_version="v[1-9]+\.[0-9]+\.[0-9]+" 306 | if [[ $meilisearch_version =~ $regex_version ]] 307 | then 308 | sed -i 's/--dumps-dir/--dump-dir/' /etc/systemd/system/meilisearch.service 309 | fi 310 | 311 | ## Restart Meilisearch 312 | systemctl restart meilisearch 313 | echo -e "${INFO_LABEL}Meilisearch $meilisearch_version is starting." 314 | 315 | # In case of failed restart rollback to initial version 316 | systemctl_status previous_version_rollback exit 317 | echo -e "${SUCCESS_LABEL}Meilisearch $meilisearch_version service started succesfully." 318 | 319 | # Delete temporary files to leave the environment the way it was initially 320 | delete_temporary_files 321 | 322 | echo -e "${BGREEN}Migration complete. Meilisearch is now in version ${NC} ${BPINK}$meilisearch_version${NC}." 323 | echo -e "${BGREEN}Meilisearch service up and running in version ${NC} ${BPINK}$meilisearch_version${NC}." 324 | --------------------------------------------------------------------------------