I would like to ask about Mnesia backup:
1. How to periodically create backup of Mnesia DB of a node?
2. How do to copy backup files to other machines and use them there?
Regards.
________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org
-- p
On Sun, 30 Aug 2009, ngocdaothanh wrote:
> Hi everyone,
>
> I would like to ask about Mnesia backup:
> 1. How to periodically create backup of Mnesia DB of a node?
You can have a gen_server which uses timer:send_interval/2 combined with
handle_info/2 to trigger the backups. You can back up everything with
mnesia:backup/1. In case the backup takes a very long time you should
twiddle something in the gen_server state to prevent starting a new backup
while an old one is happening.
> 2. How do to copy backup files to other machines and use them there?
Is this about the actual file movement, or about whether a mnesia backup
done on cluster A can be restored on cluster B?
On EC2, I store the backups on S3 via s3fs, then use mnesia:restore/2 when
I want to restore the backup. I haven't tried to restore a backup on a
cluster when all the node names have changed from when the backup was
performed.
-- p
> Inline.
>
> -- p
>
> On Sun, 30 Aug 2009, ngocdaothanh wrote:
>
> > Hi everyone,
> >
> > I would like to ask about Mnesia backup:
> > 1. How to periodically create backup of Mnesia DB of a node?
>
> You can have a gen_server which uses timer:send_interval/2 combined with
> handle_info/2 to trigger the backups. You can back up everything with
> mnesia:backup/1. In case the backup takes a very long time you should
> twiddle something in the gen_server state to prevent starting a new backup
> while an old one is happening.
>
>
No need for the timer though, just use the gen_server's own timeout return
value. Combine this with calculating a timeout value using the
until_next_time() function from crone and you can have nicely scheduled
backups.
Minimal, untested and not even compiled example, started with something like
mybackup:start_link("DB.BAK", {daily, {every, {1, hr}, {between, {12, 0, 0,
am}, {11, 59, 59, pm}}}}) .
-module(mybackup).
-behaviour(gen_server).
-export([start_link/2, init/1, handle_info/2]).
start_link(Backup_File, Backup_When) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [Backup_File,
Backup_When], []).
init([Backup_File, Backup_When]) ->
{ok, {Backup_File, Backup_When},
1000*crone:until_next_time(Backup_When)}.
handle_info(timeout, {Backup_File, Backup_When} = State) ->
mnesia:backup(Backup_File),
% HACK: Just in case it took less than a second, make sure we don't do
it again right away.
timer:sleep(1000),
{noreply, State, 1000*crone:until_next_time(Backup_When)}.
Robby
> Is this about the actual file movement, or about whether a mnesia backup done on cluster A can be restored on cluster B?
I mean for a same version of Erlang, is the default backup file cross-
platform and can be restored anywhere just like a PostgreSQL backup
file? How can I create backup file on a remote server running Ubuntu,
then restore it to my local Snow Leopard laptop? I heard somewhere
that once created a Mnesia DB will be fixed to a node name, simply
copying it doesn't work.
> until_next_time() function from crone
crone is very interesting. Where can I find the latest version of it?
Regards.
On Sep 1, 2:34 am, Robert Raschke <rtrli...@googlemail.com> wrote:
________________________________________________________________
> Thank you for the answers.
>
> > Is this about the actual file movement, or about whether a mnesia backup
> done on cluster A can be restored on cluster B?
>
> I mean for a same version of Erlang, is the default backup file cross-
> platform and can be restored anywhere just like a PostgreSQL backup
> file? How can I create backup file on a remote server running Ubuntu,
> then restore it to my local Snow Leopard laptop? I heard somewhere
> that once created a Mnesia DB will be fixed to a node name, simply
> copying it doesn't work.
>
If you just want the contents of some/all tables restored, you can use the
backup anywhere. If you want the entire database rebuilt from scratch using
the backup, the node names have to match. There is a way to change node
names in the backup file if you need the latter. Refer to the Mnesia user
guide for details.
cheers
Chandru