Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Restore-DbaDatabase is the main entry point to the restore functions.
The function itself doesn't do much apart from check paramters, pass file inputs to the correct parsing function and marshall the internal functions in order
The BEGIN section is purely concerned with checking parameters are correct.
In here we also check whether we're working locally to the target SQL Server instance or not. If we are local then all forms of file input are available. If non local then only UNC paths or local paths via Get-XpDirTreeRestoreFile
The PROCESS section is predomniantly dealing with the passed in files and paths. We can't progress until we have all the files passed in (Sod's Law states that the last file we get will be the first one we need).
The END section does the actual restore work
If not running locally use
Test-SqlPath to check that the target instance can see the requested restore paths
At this point
$BackupFiles contains all files that passed the basic filtering in the BEGIN section. For debugging, if you can uncomment the return to have the function stop here so you can see what files have been collected.
These are all passed to Get-FilteredRestoreFile, which will check they are SQL Server backup files and return them filtered down as required by parameters, grouped by database into
At this point
$AllFilteredFiles can be returned so you could peak at the raw filtered backup files.
The backup file details are group together in
$AllFilteredFiles, so we can ForEach through the array to restore each database.
If the set of backup files pass the Test-DbaLsnChain and Test-DbaRestoreVersion tests then the files are passed off to Restore-DbFromFilteredArray to perform the actual restore