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.