https://docs.microsoft.com/en-us/azure/devops/repos/git/delete-existing-repo?view=vsts
Azure SQL Backup, restore and generate Scripts
Create copy of Db on same server (SQL STATEMENT):
CREATE DATABASE [gs-app-db-cpy] AS COPY OF [gs-app-db]
SSMS Backup options for on-prem server dbs:
Backup database [md-migration-himavaan] to disk =N’c:\gBaks\him.bak’
bak : Applicable for On-premise databases backups (From SSMS or SQLOPS tool : To create a bac file we Right Click Database >> Tasks >> Backup)
Backup and restore using BacPac file:
Create bacpac file : Applicable for Backups/Export Data Tier of Databases to/within Azure SQL Databases (From SSMS or SQLOPS tool : To create a bac file we Right Click Database >> Tasks >> Export Data Tier). BacPac is not consistent if data is cont. been written while BacPac is in progress so better is to create a copy of db and then create BacPac.
IMPORT BacPac file using Azure Portal:
Upload BacPac to some storage account and use import database feature on Azure portal. Note: provide correct admin username and password for that db otherwise import will fail.
POWERSHELL COPY DB SERVER TO SERVER:
New-AzureRmSqlDatabaseCopy -ResourceGroupName “myResourceGroup” ` -ServerName $sourceserver ` -DatabaseName “MySampleDatabase” ` -CopyResourceGroupName “myResourceGroup” ` -CopyServerName $targetserver ` -CopyDatabaseName “CopyOfMySampleDatabase”
Generate DB Scripts:
This can be used to generate schema or schema and data scripts for db.
PowerShell versus ARM Templates
Setup local TFS
Install from – https://visualstudio.microsoft.com/tfs/
Once installed, url to local site – http://singhg7470:8080/tfs
search for TFS console on system to configure it:
How to connect to local instance of SQL Server Express
YourComputerName\SQLEXPRESS, windows authentication, and click connect.
Add user to Azure SQL Db
— On Master DB
CREATE LOGIN test
WITH PASSWORD = ‘340$Uuxwp7Mcxo7Khy’
— On Cutom DB
— add user
CREATE USER [test]
FOR LOGIN [test]
WITH DEFAULT_SCHEMA = dbo;
— add user to role(s) in db
ALTER ROLE db_owner ADD MEMBER [test];
https://www.mssqltips.com/sqlservertip/5242/adding-users-to-azure-sql-databases/
Azure CLI vs Powershell?
Azure CLI is open-source and platform independent. It works on Windows, Mac, Linux. But, from Jan 2018 even PowerShell can be used on other platforms.
https://stackoverflow.com/questions/45585000/azure-cli-vs-powershell
Azure Resource providers and types
When deploying resources, you frequently need to retrieve information about the resource providers and types. In this article, you learn to:
- View all resource providers in Azure
- Check registration status of a resource provider
- Register a resource provider
- View resource types for a resource provider
- View valid locations for a resource type
- View valid API versions for a resource type
You can perform these steps through the portal, PowerShell, or Azure CLI.
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-supported-services
Azure Powershell: Manage SQL Azure dbs
Single Db->Elastic Pool:
New-AzureRmSqlDatabaseCopy -ResourceGroupName “SourceResourceGroupName” -ServerName “SourceServerName” -DatabaseName “SourceDBName” -CopyResourceGroupName “TargetResourceGroupName” -CopyServerName “TargetServerName” -ElasticPoolName “TargetElasticPool” -CopyDatabaseName “NewDatabaseName”
Remove-AzureRmSqlDatabase -ResourceGroupName “RG_GSDb1” -ServerName “gsdbserverpool” -DatabaseName newdeltest2
Cmdlet | Description |
New-AzureRmSqlElasticPool | Creates an elastic database pool on a logical SQL server. |
Get-AzureRmSqlElasticPool | Gets elastic pools and their property values on a logical SQL server. |
Set-AzureRmSqlElasticPool | Modifies properties of an elastic database pool on a logical SQL server. For example, use the StorageMB property to modify the max storage of an elastic pool. |
Remove-AzureRmSqlElasticPool | Deletes an elastic database pool on a logical SQL server. |
Get-AzureRmSqlElasticPoolActivity | Gets the status of operations on an elastic pool on a logical SQL server. |
New-AzureRmSqlDatabase | Creates a new database in an existing pool or as a single database. |
Get-AzureRmSqlDatabase | Gets one or more databases. |
Set-AzureRmSqlDatabase | Sets properties for a database, or moves an existing database into, out of, or between elastic pools. |
Remove-AzureRmSqlDatabase | Removes a database. |
https://docs.microsoft.com/en-us/azure/sql-database/sql-database-elastic-pool
Azure Powershell: Basic CmdLets
Get-AzureSubscription -Current # List current subscription
Get-AzureSubscription # List all subscriptions
——————————————————————————————————————————–LOGIN
– Either: Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName GS-DevOps
Set-AzureRmContext -SubscriptionName GS-DevOps
– or: Add-AzureAccount (You can add as many accounts to Azure PowerShell)
– or: Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile C:\Users\GS\Downloads\mysubs.publishsettings
——-
Just to make sure that everything has gone right run the following cmdlet:
Get-AzureAccount / Get-AzureSubscription -Current / Get-AzureSubscription
————————————————————————
# Select Subscription
Set-AzureRmContext -SubscriptionId 38d8d050-5c50-4eba-b06b-16124ec3b55c
Select-AzureSubscription -SubscriptionName GS-Devops
Select-AzureSubscription -Current -SubscriptionName GS-Devops
———————————————————————-
To get a list of resource groups in your subscription, use Get-AzureRmResourceGroup.