3

I've got an Elixir app that uses a Mnesia database. It works fine and I can store and retrieve data no problem. I'm now looking at how to back up that database and, reading through the documentation, found that there is a :mnesia.backup function that should do what I want. However, when I call it, I get:

:mnesia.backup("myfile") {:error, {:EXIT, {:error, :function_clause}}}

And the logs show this:

[error] Mnesia(:nonode@nohost): ** ERROR ** Failed to abort backup. :mnesia_backup::abort_write["myfile"] -> {:badrecord, :backup}

That line in the log is confusing as I wasn't trying to abort the backup at all.

The :function_clause error suggests that an invalid argument is passed somewhere so I search online to see what I should pass to the backup function (the Erlang docs are particularly unclear about that) and found this question that suggests it should be the name of the backup file: what is the proper way to backup/restore a mnesia database?

I had a look at the mnesia code to see if I could find anything obvious but no joy there.

Can anybody tell me what I'm doing wrong please?

I am using Elixir 1.4.1 with Erlang/OTP 19 on Ubuntu 16.04 and I have a basic code example that demonstrates the problem if needed.

Community
  • 1
  • 1
Bruno Girin
  • 175
  • 2
  • 10
  • 2
    Try single quotes: `:mnesia.backup('myfile')`. – Dogbert Apr 27 '17 at 08:20
  • 1
    That works and proves I still need to get my head round the difference between binaries, strings and char lists in Elixir, thanks! Do you mind making this an answer so that I can accept it as the correct answer please? – Bruno Girin Apr 27 '17 at 09:44
  • 2
    Basically - Erlang doesn't have strings, just charlists, so using strings with Erlang's modules didn't work. – PatNowak Apr 27 '17 at 09:57

1 Answers1

6

:mnesia.backup accepts a charlist as the file name, which are written in double quotes in Erlang syntax but single quotes in Elixir. The following should work:

:mnesia.backup('myfile')

I'd highly recommend going through this official Elixir crash course to quickly pick up Erlang syntax if you know Elixir syntax or vice versa.

Dogbert
  • 212,659
  • 41
  • 396
  • 397