Canister Snapshot Up/Download

Canister Snapshot Up/Download

Next week, a new feature will be rolled out that allows controllers to download and upload canister snapshots. The feature is already available today (Sept. 12) on subnets csyj4 and w4asl.

dfx canister snapshot download --dir <directory> <canister_id> <snapshot_id>
downloads the given snapshot (consisting of a metadata file and binary data files) into directory.

The same directory layout can be used to upload a snapshot with:
dfx canister snapshot upload --dir <directory> <canister_id>
which returns a new snapshot ID.

These dfx commands wrap the new corresponding management canister methods. See the interface specification for details. The feature is available in dfx from version 0.29.2-beta.0.

This functionality enables novel use cases:

  • A controller can store any number of snapshots off-chain.
  • A canister’s state can be cloned or moved to a different canister, even on a different subnet.
  • Corrupted canister state can be processed off-chain, potentially recovering a thus far unrecoverable canister.

You can find a runnable example here.

Caveats

  • While this feature enables you to move canister state to another subnet, migrating canister IDs is not possible yet, but it’s being worked on.
  • Download and upload bandwidth is limited by many factors. E.g., a single chunk of data cannot exceed 1MiB. So expect download and upload to take some time.
  • The rollout is done in stages, so if you get a “not yet implemented” error, wait another day or so.

We hope you find this useful.
Please reach out in this thread for questions and feedback.

16 Likes

Super cool!

Is there also going to be a way to do this programmatically?
i.e. Clone a canister using a function call from a canister?

Yes, by using the management canister calls directly. That requires the calling canister to be controller of the target canister.

Edit: And ofc the calling canister needs to accommodate for the snapshot memory.

5 Likes

This is amazing. Exactly what I always wanted to have :slight_smile:

Addendum: Please use dfx version 0.29.2-beta.0, when using this feature (not 0.29.1 as stated originally).

The change is now rolled out on most app subnets, and rollout will be done by today EOD.

5 Likes