There is nothing automated that would do the whole thing with just one command, but it is possible.
Let’s say you’ve got two computers, ana
and bob
. You’ve got a bunch of snaps installed in ana
, and you want to have the same snaps, and the same config and etc., in bob
. First of all, install snapd
in bob
. Check that snap list
tells you there are no snaps (if there are some snaps you need to be more careful with the copying so as not to override things, hopefully you can figure that out).
After that the easiest is probably this: copy the snap cache, then get a list of snaps on ana
, copy it to bob
, and install all those snaps:
ana:~/ sudo scp -r /var/lib/snapd/cache/ bob.local:
ana:~/ snap list | awk '!/disabled/{print $1}' > ana.list
ana:~/ scp ana.list bob.local:
ana:~/ ssh bob.local
bob:~/ sudo mv -v cache/* /var/lib/snapd/cache/
bob:~/ snap install $( cat ana.list )
then, you take a ‘snapshot’ of all the data on ana
, copy it to bob
and restore it there (just to be on the safe side, make sure you’ve closed all snap apps and stopped all snap services—in bash you can do the latter with just snap stop M-*
).
So, take a snapshot on ana
, copy it to bob
, restore it there (depending on your setup you might need sudo
for part or all of this):
ana:~/ snap save
Set Snap Age Version Rev Size Notes
59 black 5m29s 19.3b0+git51.g1bbb01b 5 6.17kB -
59 bofh 5m30s 0.1 1 363B -
[... snip ...]
59 word-salad 5m29s 0.1 20 250B -
59 yq 5m30s 2.4.0 352 253B -
that 59
is important, you use it to copy it:
ana:~/ sudo scp /var/lib/snapd/snapshots/59_*.zip bob.local:
ana:~/ ssh bob.local
bob:~/ sudo mv 59_*.zip /var/lib/snapd/snapshots/
bob:~/ snap restore 59
bob:~/ sudo rm /var/lib/snapd/snapshots/59_*.zip
the last step is done because snapd
on bob
will, at some point in time, happily create its own snapshots set 59 and it might conflict with the one you’ve dumped in there.
One (perhaps obvious) caveat: if a snap writes outside of the ~/snap/<snapname>/
directory, either via an interface (like home
, removable-media
, personal-files
, etc., etc.), or via being a devmode or classic snap, then this data won’t be picked up by snap save
, and so won’t be restored by snap restore
.
For this to work you need bob
to be able to access the internet. If you can’t, you can use snap known
on ana
to get all the assertions, and then feed to bob
via snap ack
. You’d use GO_FLAGS_COMPLETION=1 snap known ""
to get the list of assertion types, then iterate over that with snap known <type>
, save all that to a file, and pipe it into snap ack
on bob. That should work.
<BLINK> ALL OF THIS IS UNTESTED AND WRITTEN FROM MEMORY </BLINK>
(not the commands, we test those thousands of times a day – i mean using them to transfer things between machines like this is untested. None of it should be destructive though; please let me know how it goes!)