|
| 1 | +Pad migration guide from etherpad-lite |
| 2 | +=== |
| 3 | + |
| 4 | +The goal of this migration is to do a "dumb" import from all the pads in Etherpad, to notes in |
| 5 | +CodiMD. In particular, the url locations of the pads in Etherpad will be lost. Furthermore, any |
| 6 | +metadata in Etherpad, such as revisions, author data and also formatted text will not be migrated |
| 7 | +to CodiMD (only the plain text contents). |
| 8 | + |
| 9 | +Note that this guide is not really meant as a support guide. I migrated my own Etherpad to CodiMD, |
| 10 | +and it turned out to be quite easy in my opinion. In this guide I share my experience. Stuff may |
| 11 | +require some creativity to work properly in your case. When I wrote this guide, I was using |
| 12 | +[Etherpad 1.7.0] and [CodiMD 1.2.1]. Good luck! |
| 13 | + |
| 14 | +[Etherpad 1.7.0]: https://github.com/ether/etherpad-lite/tree/1.7.0 |
| 15 | +[CodiMD 1.2.1]: https://github.com/hackmdio/codimd/tree/1.2.1 |
| 16 | + |
| 17 | +## 0. Requirements |
| 18 | + |
| 19 | +- `curl` |
| 20 | +- running Etherpad server |
| 21 | +- running CodiMD server |
| 22 | +- [codimd-cli] |
| 23 | + |
| 24 | +[codimd-cli]: https://github.com/hackmdio/codimd-cli/blob/master/bin/codimd |
| 25 | + |
| 26 | +## 1. Retrieve the list of pads |
| 27 | + |
| 28 | +First, compose a list of all the pads that you want to have migrated from your Etherpad. Other than |
| 29 | +the admin interface, Etherpad does not have a dedicated function to dump a list of all the pads. |
| 30 | +However, the Etherpad wiki explains how to list all the pads by [talking directly to the |
| 31 | +database][howtolistallpads]. |
| 32 | + |
| 33 | +You will end up with a file containing a pad name on each line: |
| 34 | + |
| 35 | +``` |
| 36 | +date-ideas |
| 37 | +groceries |
| 38 | +london |
| 39 | +weddingchecklist |
| 40 | +(...) |
| 41 | +``` |
| 42 | + |
| 43 | +[howtolistallpads]: https://github.com/ether/etherpad-lite/wiki/How-to-list-all-pads/49701ecdcbe07aea7ad27ffa23aed0d99c2e17db |
| 44 | + |
| 45 | +## 2. Run the migration |
| 46 | + |
| 47 | +Download [codimd-cli] and put the script in the same directory as the file containing the pad names. |
| 48 | +Add to this directory the file listed below, I called it `migrate-etherpad.sh`. Modify at least the |
| 49 | +configuration settings `ETHERPAD_SERVER` and `CODIMD_SERVER`. |
| 50 | + |
| 51 | +```shell |
| 52 | +#!/bin/sh |
| 53 | + |
| 54 | +# migrate-etherpad.sh |
| 55 | +# |
| 56 | +# Description: Migrate pads from etherpad to codimd |
| 57 | +# Author: Daan Sprenkels <[email protected]> |
| 58 | + |
| 59 | +# This script uses the codimd command line script[1] to import a list of pads from |
| 60 | +# [1]: https://github.com/hackmdio/codimd-cli/blob/master/bin/codimd |
| 61 | + |
| 62 | +# The base url to where etherpad is hosted |
| 63 | +ETHERPAD_SERVER="https://etherpad.example.com" |
| 64 | + |
| 65 | +# The base url where codimd is hosted |
| 66 | +CODIMD_SERVER="https://codimd.example.com" |
| 67 | + |
| 68 | +# Write a list of pads and the urls which they were migrated to |
| 69 | +REDIRECTS_FILE="redirects.txt" |
| 70 | + |
| 71 | + |
| 72 | +# Fail if not called correctly |
| 73 | +if (( $# != 1 )); then |
| 74 | + echo "Usage: $0 PAD_NAMES_FILE" |
| 75 | + exit 2 |
| 76 | +fi |
| 77 | + |
| 78 | +# Do the migration |
| 79 | +for PAD_NAME in $1; do |
| 80 | + # Download the pad |
| 81 | + PAD_FILE="$(mktemp)" |
| 82 | + curl "$ETHERPAD_SERVER/p/$PAD_NAME/export/txt" >"$PAD_FILE" |
| 83 | + |
| 84 | + # Import the pad into codimd |
| 85 | + OUTPUT="$(./codimd import "$PAD_FILE")" |
| 86 | + echo "$PAD_NAME -> $OUTPUT" >>"$REDIRECTS_FILE" |
| 87 | +done |
| 88 | +``` |
| 89 | + |
| 90 | +Call this file like this: |
| 91 | + |
| 92 | +```shell |
| 93 | +./migrate-etherpad.sh pad_names.txt |
| 94 | +``` |
| 95 | + |
| 96 | +This will download all the pads in `pad_names.txt` and put them on CodiMD. They will get assigned |
| 97 | +random ids, so you won't be able to find them. The script will save the mappings to a file though |
| 98 | +(in my case `redirects.txt`). You can use this file to redirect your users when they visit your |
| 99 | +etherpad using a `301 Permanent Redirect` status code (see the next section). |
| 100 | + |
| 101 | +## 3. Setup redirects (optional) |
| 102 | + |
| 103 | +I got a `redirects.txt` file that looked a bit like this: |
| 104 | + |
| 105 | +``` |
| 106 | +date-ideas -> Found. Redirecting to https://codimd.example.com/mPt0KfiKSBOTQ3mNcdfn |
| 107 | +groceries -> Found. Redirecting to https://codimd.example.com/UukqgwLfhYyUUtARlcJ2_y |
| 108 | +london -> Found. Redirecting to https://codimd.example.com/_d3wa-BE8t4Swv5w7O2_9R |
| 109 | +weddingchecklist -> Found. Redirecting to https://codimd.example.com/XcQGqlBjl0u40wfT0N8TzQ |
| 110 | +(...) |
| 111 | +``` |
| 112 | + |
| 113 | +Using some `sed` magic, I changed it to an nginx config snippet: |
| 114 | + |
| 115 | +``` |
| 116 | +location = /p/date-ideas { |
| 117 | + return 301 https://codimd.example.com/mPt0M1KfiKSBOTQ3mNcdfn; |
| 118 | +} |
| 119 | +location = /p/groceries { |
| 120 | + return 301 https://codimd.example.com/UukqgwLfhYyUUtARlcJ2_y; |
| 121 | +} |
| 122 | +location = /p/london { |
| 123 | + return 301 https://codimd.example.com/_d3wa-BE8t4Swv5w7O2_9R; |
| 124 | +} |
| 125 | +location = /p/weddingchecklist { |
| 126 | + return 301 https://codimd.example.com/XcQGqlBjl0u40wfT0N8TzQ; |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +I put this file into my `etherpad.example.com` nginx config, such that all the users would be |
| 131 | +redirected accordingly. |
0 commit comments