1
votes

Problem statement

I have a mnesia backup file and would like to extract values from it. There are 3 tables(to make it simple), Employee, Skills, and attendance. So the mnesia back up file contains all those data from these three tables.

Emplyee table is :

Empid (Key) 
Name
SkillId
AttendanceId

Skill table is

SkillId (Key)
Skill Name

Attendance table is

Code (Key)
AttendanceId
Percentage

What i have tried I have used

ets:foldl(Fetch,OutputFile,Table)

Fetch : is separate function to traverse the record fetched to bring in desired output format.

OutputFile : it writes to this file

Table : name of the table

Expecting

I am gettig records with AttendanceId(as this is the key) where as i Want to get code only. It displays employee informations and attendance id.

Help me out.

1
How did you get your file? If with mnesia:backup, you should use mnesia:restore, or mnesia:traverse_backup - Lol4t0
I am not restoring back to another mnesia database. Instead I need to extract some fields from backup to a file. - Madhusudan Joshi

1 Answers

1
votes

Backup and restore is described in the mnesia user guide here.

To read an existing backup, without restoring it, use mnesia:traverse_backup/4.

1> mnesia:backup(backup_file).
ok
2> Fun = fun(BackupItems, Acc) -> {[], []} end.
#Fun<erl_eval.12.90072148>
3> mnesia:traverse_backup(backup_file, mnesia_backup, [], read_only, Fun, []).
{ok,[]}

Now add something to the Fun to get what you want.