Skip to content

Backing up and restoring databases

TSGrid supports snapshots, allowing you to reset a database to given state at any time.

Creating a snapshot

You create a snapshot by making a POST request to /admin/snapshots, passing a JSON document:

database The name of the database to be backed up
path The file system path where the snapshot should be stored e.g. /mnt/tsgrid/data/backups/testdb
message A message that describes the snapshot e.g. "before bulk load"

Tip

The path is significant as TSGrid builds snapshots on top of each other. It's best to use the same path for a given database. This allows TSGrid to snapshot the deltas, not the entire database.

Request:

POST /admin/snapshots HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
  "database": "page-visits",
  "path": "/mnt/tsgrid/data/snapshots/page-visits",
  "message": "Before bulk load"
}

Response:

Content-Type: application/json
Transfer-Encoding: chunked

{
  "id": 1,
  "timestamp": "2020-04-28T14:12:11Z",
  "path": "/mnt/tsgrid/data/snapshots/page-visits",
  "message": "Before bulk load"
}

Listing snapshots

You can see the snapshots at a given path by making a GET request to /admin/snapshots, passing a JSON document:

path - The file system path where the snapshot is stored e.g. /mnt/tsgrid/data/backups/page-visits

Request:

GET /admin/snapshots HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
  "path": "/mnt/tsgrid/data/snapshots/testdb"
}

Response:

Content-Type: application/json
Transfer-Encoding: chunked

[
  {
    "id": 2,
    "timestamp": "2020-04-28T15:12:11Z",
    "path": "/mnt/tsgrid/data/snapshots/page-visits",
    "message": "After bulk load"
  },
  {
    "id": 1,
    "timestamp": "2020-04-28T14:12:11Z",
    "path": "/mnt/tsgrid/data/snapshots/page-visits",
    "message": "Before bulk load"
  }
]

Tip

Snapshots at a given path are returned in reverse chronological order

Restoring from a snapshot

The database can be restored to a previous state by making a POST request to /admin/snapshots/restore with a JSON payload:

database The database to which the snapshot should be applied
path The file system path where the snapshot is stored e.g. /mnt/tsgrid/data/backups/page-visits
id Optional - the snapshot id to be applied. If no id is given the latest snapshot will be applied

Request:

POST /admin/snapshots/restore HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
  "database": "testdb",
  "path": "/mnt/tsgrid/data/backups/page-visits",
  "id": 1
}

Response:

Content-Type: application/json
Transfer-Encoding: chunked

{
  "status": "success"
}

Deleting snapshots

Snapshots at a given path can be deleted by making a DELETE request to /admin/snapshots with a JSON payload:

path - The file system path where the snapshots are stored e.g. /mnt/tsgrid/data/backups/page-visits

Request:

DELETE /admin/snapshots HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
  "path": "/mnt/tsgrid/data/backups/page-visits"
}

Response:

Content-Type: application/json
Transfer-Encoding: chunked

[
  {
    "id": 2,
    "timestamp": "2020-04-28T15:12:11Z",
    "path": "/mnt/tsgrid/data/snapshots/page-visits",
    "message": "After bulk load"
  },
  {
    "id": 1,
    "timestamp": "2020-04-28T14:12:11Z",
    "path": "/mnt/tsgrid/data/snapshots/page-visits",
    "message": "Before bulk load"
  }
]