# Snapshots and forks with the Tigris SDK

This page covers using snapshots and forks with the Tigris JavaScript SDK. For an overview of the concepts, see [Snapshots](/docs/snapshots/.md) and [Forks](/docs/forks/.md). For using snapshots and forks with other SDKs (Go, Python), see [Bucket Snapshots and Forks](/docs/buckets/snapshots-and-forks/.md).

Tigris SDK provides a way to create and manage snapshots and forks using a simple API.

## Create a bucket with snapshots enabled[​](#create-a-bucket-with-snapshots-enabled "Direct link to Create a bucket with snapshots enabled")

A bucket with snapshots enabled can be created using the `createBucket` function.

```
import { createBucket } from "@tigrisdata/storage";



const result = await createBucket("llm-base", {

  enableSnapshot: true,

});



if (result.error) {

  console.error("error creating bucket", result.error);

} else {

  console.log("bucket created with snapshots enabled");

}
```

## Snapshots[​](#snapshots "Direct link to Snapshots")

### Create a snapshot from the bucket[​](#create-a-snapshot-from-the-bucket "Direct link to Create a snapshot from the bucket")

A snapshot can be created from the bucket using the `createBucketSnapshot` function.

```
import { createBucketSnapshot } from "@tigrisdata/storage";



await createBucketSnapshot("llm-base", {

  name: "pre-finetune", // optional name for the snapshot

});
```

### List snapshots of a bucket[​](#list-snapshots-of-a-bucket "Direct link to List snapshots of a bucket")

A list of snapshots for the bucket can be retrieved using the `listBucketSnapshots` function.

```
import { listBucketSnapshots } from "@tigrisdata/storage";



const result = await listBucketSnapshots("llm-base");



if (result.error) {

  console.error("Error listing snapshots:", result.error);

} else {

  console.log("Snapshots:");

  result.data.forEach((snapshot) => {

    console.log(`- ${snapshot.version}: ${snapshot.creationDate}`);

  });

}
```

### List objects in a snapshot[​](#list-objects-in-a-snapshot "Direct link to List objects in a snapshot")

Objects in a snapshot can be listed using the `list` function.

```
import { list } from "@tigrisdata/storage";



const result = await list("llm-base", {

  snapshotVersion: "1760550614083112540",

});
```

## Forks[​](#forks "Direct link to Forks")

Fork is a new bucket created from an existing one, sharing data without duplication.

### Create a fork from the bucket[​](#create-a-fork-from-the-bucket "Direct link to Create a fork from the bucket")

Forks can be created using the `createBucket` function and by passing `sourceBucketName` in the `options`.

```
import { createBucket } from "@tigrisdata/storage";



const createFork = await createBucket(

  "llm-fork", // name of the fork bucket being created

  {

    sourceBucketName: "llm-base", // name of the source bucket

  },

);



if (createFork.error) {

  console.error("error creating bucket fork", createFork.error);

} else {

  console.log("bucket fork created");

}
```

### Create a fork from the bucket with a specific snapshot[​](#create-a-fork-from-the-bucket-with-a-specific-snapshot "Direct link to Create a fork from the bucket with a specific snapshot")

```
import { createBucket } from "@tigrisdata/storage";



const forkName = "llm-fork";

const sourceBucketName = "llm-base";

const sourceBucketSnapshot = "1760550614083112540";



const fromSnapshot = await createBucket(forkName, {

  sourceBucketName: sourceBucketName,

  sourceBucketSnapshot: sourceBucketSnapshot,

});



if (fromSnapshot.error) {

  console.error("error creating bucket fork", fromSnapshot.error);

} else {

  console.log("bucket fork created");

}
```

note

If you don't provide the bucket name in the `sourceBucketName` parameter, it will use the bucket name from either `.env` or environment variables.

```
import { createBucketSnapshot, listBucketSnapshots } from "@tigrisdata/storage";



await createBucketSnapshot({

  name: "pre-finetune", // optional name for the snapshot

});



await listBucketSnapshots();
```

## Getting an object from a snapshot[​](#getting-an-object-from-a-snapshot "Direct link to Getting an object from a snapshot")

An object from a snapshot can be retrieved using the `get` function.

```
import { get } from "@tigrisdata/storage";



const result = await get("object.txt", {

  snapshotVersion: "1760550614083112540",

});
```

Similarly, `head` function can be used to get the metadata of an object from a specific snapshot.

```
import { head } from "@tigrisdata/storage";



const result = await head("object.txt", {

  snapshotVersion: "1760550614083112540",

});
```
