Fixing restore folder see BT#8022.

When creating a folder we check if the folder exists and is registered
in the database.