|
| 1 | +# Data migration |
| 2 | + |
| 3 | +From v4.0.26 onwards, scripts are included for exporting and importing data of individual guilds. |
| 4 | +This allows migrating between databases or instances of the bot. |
| 5 | + |
| 6 | +## Exporting data |
| 7 | + |
| 8 | +To dump a single guild's data, run the following command in the bot's base directory: |
| 9 | + |
| 10 | +=== "npm" |
| 11 | + ```bash linenums="0" |
| 12 | + npm run bot.export -- -g <guild_id> |
| 13 | + ``` |
| 14 | +=== "pnpm" |
| 15 | + ```bash linenums="0" |
| 16 | + pnpm run bot.export -g <guild_id> |
| 17 | + ``` |
| 18 | + |
| 19 | +Note that this command requires the database and encryption key environment variables to be set. |
| 20 | +This command writes a single file and prints the path to it. |
| 21 | + |
| 22 | +!!! example |
| 23 | + ```bash linenums="0" |
| 24 | + $ npm run bot.export -- -g 810934178946351174 |
| 25 | + |
| 26 | + |
| 27 | + > node scripts/export.mjs -g 810934178946351174 |
| 28 | + |
| 29 | + ✔ Connected |
| 30 | + ✔ Exported settings |
| 31 | + ✔ Exported 3 categories |
| 32 | + ✔ Exported 1 tags |
| 33 | + ✔ Exported 9 tickets |
| 34 | + ✔ Written to "/home/container/user/dumps/80b5069d711591431db37f6a22742c73c1df44.dump" |
| 35 | + ``` |
| 36 | + |
| 37 | +!!! danger |
| 38 | + The file is lightly encrypted but **the encryption key is the guild ID**. |
| 39 | + Do not share the file publicly. |
| 40 | + |
| 41 | +!!! warning |
| 42 | + **Do not rename the file.** The filename is a hash of the guild ID and must not be changed for the import script to work. |
| 43 | + |
| 44 | +## Importing data |
| 45 | + |
| 46 | +If moving from another instance, copy the guild's dump file into `user/dumps`. |
| 47 | + |
| 48 | +Run the following command in the bot's base directory: |
| 49 | + |
| 50 | +=== "npm" |
| 51 | + ```bash linenums="0" |
| 52 | + npm run bot.import -- -g <guild_id> |
| 53 | + ``` |
| 54 | +=== "pnpm" |
| 55 | + ```bash linenums="0" |
| 56 | + pnpm run bot.import -g <guild_id> |
| 57 | + ``` |
| 58 | + |
| 59 | +## Migrating from SQLite |
| 60 | + |
| 61 | +The data migration scripts can be used to move from SQLite to another database. |
| 62 | + |
| 63 | +1. [Export](#exporting-data) all guilds |
| 64 | +2. Modify the [`DB_PROVIDER`](configuration.md#db_provider) and [`DB_CONNECTION_URL`](./configuration.md#db_connection_url) environment variables |
| 65 | +3. Run `npm run postinstall` |
| 66 | +4. [Import](#importing-data) all guilds |
0 commit comments