In SharePoint 2010 you can save a site as template from the _layouts/savetmpl.aspx utility page. It creates a wsp file than you can download, and deploy in other SharePoint farm to create new sites based on the same template.
But what if you need to create a site collection template? You could need this, for example, in the you want the restored site is the first site of the first site collection of a new web application.
In the blog post How to Build a Site Collection Template from A Web Template in SharePoint 2010 I've found the solution, based on importing the wsp in Visual Studio and changing a few settings (feature scopes and template definition)