Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (25 sloc) 1.02 KB
description
The Type-DB backup system generate a JSON string or file that can be imported at anytime.

Backup / Restore

Introduction

To backup your data you need to use the methods Save() and Restore() of the Database object.

Basic Example

{% code-tabs %} {% code-tabs-item title="backup-example.cs" %}

using (var tdb = new TypeDB.Core(Mode.Standalone).Connect())
using (var testdb = tdb.OpenDatabase("test", true))
{
    testdb.Set<string>("hello", "world");

    var backup = testdb.Save();    // export all entities in a JSON string
    
    testdb.RestoreFromFile(@"c:\backup.json");    // restore an old backup from file
}

{% endcode-tabs-item %} {% endcode-tabs %}

Backup on the fly or no

By default the Save() and Restore() methods return or restore datas from string but if you want to backup or restore to a file, you need to use SaveAs() and RestoreFromFile()

Please make sur to save in an existent location, otherwise a TypeDBGeneralException exception will be thrown.

You can’t perform that action at this time.