Can anyone explain in detail what is really going on(under the hood) during exexuting
Backup-SPSite powershell cmdlet ?
Backup-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
You should not try to build your own backup-solution programatically. It is not supported to query SharePoint-Databases directly.
There are tons of APIs and methods to code against SharePoint. They also exist for backing up SharePoint-Sites. You should make use of them.