If you run GBrain on your own computer, you can move its notes into a
workspace without losing anything that is already there. The move has five
parts:

1. Back up the workspace.
2. Export your GBrain.
3. Send the export to the workspace.
4. Import it.
5. Check the result, then clean up.

Every command runs in a terminal on your computer. Nothing is changed in the
workspace until the import, and by then you have a copy of everything it held.
Going the other way, from a workspace to your own computer, is [Move your
GBrain out of a workspace](/docs/workspace/export).

## Set up gbrainio

Every command on this page runs through gbrainio, GBrain's command line. It
installs in one line and needs nothing else on your computer.

1. **Install it.**

   ```bash
   curl -sSL https://gbrainio.terminalwire.sh | bash
   ```

2. **Sign in.** Run `gbrainio login`. It opens your browser; approve it there,
   and choose the workspace you're moving into. If the browser doesn't
   open, the command prints a link to paste into one.

3. **Get shell access.** An admin of the workspace turns it on for you under
   Shell in its settings. Free workspaces can't turn it on.
   `gbrainio workspace shell <id> open` prints that page's address.

4. **Find the workspace's id.** `gbrainio workspace ls` lists the workspaces you
   can reach, with their ids and whether shell access is on.

Your notes come from the GBrain already running on your computer, so the only
new thing to install is gbrainio.

## Make a folder for the move

Keep the id in a variable so the commands below can be pasted as written, and
make a folder for the move:

```bash
WS=652
mkdir -p ~/gbrain-move && cd ~/gbrain-move
```

Use your workspace's id in place of `652`.

The commands that run inside the workspace are in single quotes. The quotes
stop your own shell from reading `$`, `~` or `>` in them, so those reach the
workspace as written.

## Compare GBrain versions

```bash
gbrain --version
gbrainio workspace shell $WS -- gbrain --version
```

The two don't have to match. The move carries your notes as markdown files,
which every version of GBrain reads, rather than a database dump, which only
loads into the version that wrote it. The versions are worth knowing in case
something looks off later. Workspaces move to new GBrain versions on GBrain's
schedule, after each release is tested, so a workspace is often a release or
two behind the newest one.

## 1. Back up the workspace

Take two copies of what the workspace holds now, onto your computer:

```bash
gbrainio workspace shell $WS -- 'rm -rf /data/move-backup && gbrain export --dir /data/move-backup'
gbrainio workspace shell $WS -- 'tar czf - -C /data/move-backup .' > workspace-notes.tar.gz
gbrainio workspace shell $WS -- 'pg_dump -h 127.0.0.1 -U gbrain -Fc gbrain' > workspace-database.dump
```

- **`workspace-notes.tar.gz`** is every note as a markdown file. This is the
  copy you can put back yourself, the same way the move works.
- **`workspace-database.dump`** is the whole database under Memory, including
  links, facts, timelines and earlier versions of each note. If you ever need
  the workspace exactly as it was, send this file to
  [support@gbrain.io](mailto:support@gbrain.io).

Note how many notes the workspace has before the move:

```bash
gbrainio workspace shell $WS -- gbrain stats
```

```
Pages:     31
Chunks:    41
Embedded:  41
```

## 2. Export your GBrain

On your computer:

```bash
gbrain export --dir ~/gbrain-move/notes
```

It ends with a count, like `Exported 1204 pages to /Users/you/gbrain-move/notes/`.
Count the files to be sure they're all there:

```bash
find notes -name '*.md' | wc -l
```

## Check for notes in both places

A note's path is its name, like `people/jane-doe`. When the workspace already
has a note at the same path, the import replaces it with yours. List the paths
on both sides and compare them:

```bash
gbrainio workspace shell $WS -- 'gbrain list --limit 100000' | cut -f1 | sort > workspace-paths.txt
(cd notes && find . -name '*.md' | sed 's|^\./||; s|\.md$||' | sort) > my-paths.txt
comm -12 workspace-paths.txt my-paths.txt
```

If the last command prints nothing, no note will be replaced. If it prints
paths, those notes will become your versions. The workspace's versions are in
`workspace-notes.tar.gz`. To keep both, rename your copies in `notes` before
the next step.

## 3. Send the export to the workspace

```bash
COPYFILE_DISABLE=1 tar --no-xattrs -czf - -C notes . | gbrainio workspace shell $WS -- 'mkdir -p /data/move-in && tar xzf - -C /data/move-in'
```

The export goes through the terminal compressed and is unpacked in the
workspace. `COPYFILE_DISABLE=1` and `--no-xattrs` keep macOS from adding its
hidden `._` files and file attributes to the archive; on Linux they change
nothing.

Check that the same number of files arrived:

```bash
gbrainio workspace shell $WS -- 'find /data/move-in -name "*.md" | wc -l'
```

## 4. Import it

```bash
gbrainio workspace shell $WS -- 'gbrain import /data/move-in'
```

GBrain reads every file, files each note, and indexes it for search. It ends
like this:

```
Import complete (41.2s):
  1204 pages imported
  0 pages skipped (0 unchanged, 0 errors, 0 malformed filenames)
  1611 chunks created
```

A large export can take a while, and closing the terminal stops an import
running in it. For thousands of notes, start it in the background and check
on it:

```bash
gbrainio workspace shell $WS -- 'setsid nohup gbrain import /data/move-in < /dev/null > /data/move-in.log 2>&1 &'
gbrainio workspace shell $WS -- 'tail -5 /data/move-in.log'
```

Running the import again is safe. Notes that are already in skip as
unchanged, so a second run picks up only what the first one missed.

Indexing notes for search uses a little of the workspace's AI credit. For
notes of typical length, a few thousand cost well under a dollar.

## 5. Check the result

**The count.** Run `gbrain stats` again:

```bash
gbrainio workspace shell $WS -- gbrain stats
```

`Pages` should be the count from before the move, plus your export, minus any
paths the comparison found in both places. `Embedded` catches up to `Chunks`
over the next few minutes as search indexing finishes. If it stays behind,
finish it by hand:

```bash
gbrainio workspace shell $WS -- 'gbrain embed --stale'
```

**A search.** Look for something you know is in your notes:

```bash
gbrainio workspace shell $WS -- 'gbrain search "a phrase from one of your notes"'
```

**Memory.** Open the workspace's [Memory](/docs/workspace/memory) on the web.
Your folders are there, and a note opens to its text.

**The assistant.** Ask about something only your notes would know. It answers
from Memory and names the note.

## Clean up

Once the workspace looks right, remove the files the move left in it:

```bash
gbrainio workspace shell $WS -- 'rm -rf /data/move-in /data/move-in.log /data/move-backup'
```

The folder on your computer holds the backups and your export. Either move it
somewhere you keep backups, or delete it when you no longer need it:

```bash
rm -rf ~/gbrain-move
```

## Putting the workspace back

To undo the move, send the backup in and import it the same way. Notes that
the move replaced go back to the workspace's versions:

```bash
gbrainio workspace shell $WS -- 'rm -rf /data/restore && mkdir -p /data/restore'
gbrainio workspace shell $WS -- 'tar xzf - -C /data/restore' < workspace-notes.tar.gz
gbrainio workspace shell $WS -- 'gbrain import /data/restore && rm -rf /data/restore'
```

Notes that came only from your export stay. For the workspace exactly as it
was, everything else included, write to
[support@gbrain.io](mailto:support@gbrain.io) with `workspace-database.dump`.