Test setup: Incus server backup and restore profiles, networks and instances

Hello all,

I am developing a networking product and want to add E2E testing for that. I was researching for some test setup options, where I can simulate different network scenarios like packet loss, multiple routes, mtu change etc.

I recently found incus, which looks like a excellent choice for my usecase.

I have created a network with multiple containers manually and caters for my testing. And it is working fine.

But I want to way to replicate this setup, i.e I want to dump the incus config and restore in CI machines to create the exact setup and run E2E on top of it.

I just want the containers to be created with all the profiles, and networks. I can run python script to push my software along with configuration in all the containers.

I found this document, which mentions I can backup and restore the sql for config:

I have taken the backup, but I am struggling to restore in the new machine.

maari@debian ~> sudo incus admin sql local - < incus.local.sql
Error: Failed to exec query: cannot start a transaction within a transaction
maari@debian ~ [1]> sudo incus admin sql local - < incus.local.sql
Error: Failed to exec query: cannot start a transaction within a transaction
maari@debian ~ [1]> 
maari@debian ~ [1]> vim incus.local.sql 
maari@debian ~> sudo incus admin sql local - < incus.local.sql
Error: Failed to exec query: table schema already exists
maari@debian ~ [1]> 

Does backing up sql enough for my usecase, or is there any other way I can achieve the same ?

The general recommendation is to stick with Incus API calls for such kind of scenarios.

There are a lot of test examples on Github incus/test at main · lxc/incus · GitHub They should give you an idea how to build scripts for your scenario. An alternative approach would be to use Terraform, Ansible, etc. see Third party tools and integrations - Incus documentation

You can run early database commands by putting a file at /var/lib/incus/database/patch.local.sql (for local) or /var/lib/incus/database/patch.global.sql (for global).

But note that the database at that point will already be partly populated, so your .sql should either start by deleting everything or skip things like schema creation.

1 Like

Thank you @osch / @stgraber

I tried the alternate approach of using terraform for setting up the setup and it seems pretty reasonable for my usecase.

I can build and destroy, restore the build setup using terraform apply and destroy command.