Snap refresh from local file

I have installed snap using the following command:

sudo snap install --devmode my-snap.snap

However I want to check if post-refresh hook is correctly working. Without using snap store how do I refresh from a local .snap file?

You run the install command again, exactly how it appears above.

Hello thanks for this solution. But this is creating two SNAP_DATA folders x1 & x2. All of my source code resides and service has to start from SNAP_DATA folder due to read-only issues. After a refresh cycle does it create a new SNAP_DATA? I want to use the same folder across all refresh cycles without getting deleted by snap. Does SNAP_COMMON gets deleted/reset on every refresh cycles?

$SNAP_DATA and $SNAP_USER_DATA are cloned each refresh into a new folder. The data isn’t lost, it’s just placed elsewhere to create a clear separation of old VS new. This allows the snap revert command to rollback the snap image itself, and also any configuration data that might be version specific.

$SNAP_COMMON and $SNAP_USER_COMMON do not have the same behaviour, there is only ever one version of these folders and its location is not changed on a refresh. It’s designed for data that isn’t necessarily version specific.

While it sounds like the common folders would achieve what you wish, the versioned folders do have the advantages of working with the revert functionality. In an ideal world, all references to these folders would be based on the environment variables and so you shouldn’t really notice that the versioned folders are in fact versioned.

For $SNAP_COMMON folder is data lost during refresh?

No, $SNAP_COMMON is not modified during a refresh. However I’m confused as to why the data appears to be lost in $SNAP_DATA, the data is copied to a new location as is, but it isn’t deleted. The folder X2 should contain the same data as X1 when the refresh is completed.

The folder X1 itself will be purged when X3 is installed, but the data inside it would still be in X3.

Okay thanks for clarifying. Yes you are right data is not lost in $SNAP_DATA.

Hello one last thing. I use $SNAP_DATA to run a snap service which has refresh set to endure. Due to cloning from x1 to x2, will my service suffer any downtime? Actually my entire stateful application resides in $SNAP_DATA and my snap service is started from this folder.

During cloning from x1 to x2 is there a possibility that some of the data in x1 will never be copied to x2? Since my service will continue writing in x1 till cloning finishes.