This script uses dbatools to backup database objects from a SQL Server Database to a directory of your choosing. This script is used internally to backup our databases for GitHub.
The server & database are both user defined parameters.
Parameter | Data Type | Mandatory |
---|---|---|
database | string | Yes |
server | string | Yes |
SourceControlDirectory | string | Yes |
logDirectory | string | Yes |
- Clone the code to your local workstation.
- Navigate to the directory where the script has been cloned
- Execute the script passing in the required parameters.
.\SQL-Schema-Backup.ps1 -database 'YourDatabase' -server 'YourServer' -SourceControlDirectory 'C:\Temp\' -logDirectory 'C:\Temp\Logs' -pushToGit $True
.\SQL-Schema-Restore.ps1 -database 'YourDatabase' -server 'YourServer' -SourceControlDirectory 'C:\Temp\' -logDirectory 'C:\Temp\Logs'
These scripts make use of smo.scriptingoptions