I can snapshot a LXC on a ZFS Pool with or without the Option "Stateful". I can not find any Info about it. What does it mean?
2 Answers
Applications (or services etc.) can have a state. That's basically the condition the application is in, typically because of what happened to it in the past.
You can distinguish between stateful and stateless applications. In a stateless application, the task at hand can be done without considering the current state of the application. If the task is interrupted, it can just be tried again.
Let's imagine a simple web server. Your browser requests the file welcome.html, and the server delivers that file. To perform this task, the server doesn't need to consider who requested which files before, who you are, what you did before etc. If the web server gets shut down in the middle of sending you the file, you can just request the file again after the server is up again.
On the other hand, with a stateful the past matters, so to speak. The outcome of a task depends on the state the application is in when the task was started. If the task is interrupted, the state needs to be stored in some fashion and maybe recreated before the next try.
Let's imagine a web server that's a bit more sophisticated: Before you can request a file, you have to log in. If you're not logged in, the server won't deliver welcome.html to you. So when your browser requests the file, the server needs to consider the past. Did you log in, or did you not? If so, which user account are you logged in as? And so forth. If the web server gets shut down in the middle of sending you the file, it needs to recreate that state, that outcome of the past, before the next try.
If an application is inside a container, similar considerations apply to the container. Let's say you containerize the first, the simple web server. In this case, you don't have to think about where to store the application's state, how to include the state in a backup, how to restore the state when a backup is restored, how to transfer the state when you transfer the container to a different host etc. You might say, that container is stateless itself.
If you containerize the second, more sophisticated web server, you need to consider its state. You need to consider all those questions about storing, backing up, restoring, transfering, ... the state of whatever is in the container. You might say, that container is stateful itself.
So to put it shortly, a stateful container contains something (an application, a service, ...) that's stateful. The container and operations on the container need to take the state into consideration. A stateless container contains something that's stateless. The container and operations on the container don't need to take the state into consideration.
1Stateful snapshots in LXD require to enable CRIU (not enabled by default in the LXD snap package).
The purpose of stateful snapshots is to take a snapshot of a live container and then either restore on the same LXD installation or more interestingly to a remote LXD installation.
1