Skip to content

Instantly share code, notes, and snippets.

View geralexgr's full-sized avatar

Gerasimos Alexiou geralexgr

View GitHub Profile
import os, uuid
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
connection_string = "CONNECTION_STRING"
service = BlobServiceClient.from_connection_string(connection_string)
try:
account_info = service.get_account_information()
print('Using Storage SKU: {}'.format(account_info['sku_name']))
$folder_for_cleanup = "R:\files\incremental"
Get-ChildItem $folder_for_cleanup | Sort -Property FullName | ForEach-Object {
Write-Host restoring $_.FullName
sqlcmd -Q "RESTORE LOG [Database_Name] FROM DISK=N'$_' WITH NORECOVERY" -o R:\files\results\incrementalresult.txt; #writing a log output
[string]$result = Get-Content R:\files\results\incrementalresult.txt
if ($result.contains('terminates')) {
Write-Host backup is already present in the database, skipping ...
Remove-Item $_.FullName -Force -Confirm:$false
}
else {
trigger:
- none
pool:
vmImage: windows-latest
steps:
- task: VSBuild@1
displayName: Build appservice
trigger: none
pr: none
pool:
vmImage: windows-latest
parameters:
- name: backupfile
type: string
jobs:
- task: AzureCLI@2
displayName: az cli stop command
inputs:
azureSubscription: 'YOURSUB'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$token = az account get-access-token | ConvertFrom-Json
$mytoken = $token.accesstoken
trigger: none
pr: none
parameters:
- name: vms
type: object
default: ["ubuntu1","windows-1"]
pool:
vmImage: ubuntu-latest
$container_name_input = "backups"
$sg_con_string = "XXX"
$json = az storage blob list --container-name $container_name_input --connection-string $sg_con_string | ConvertFrom-Json | Sort-Object -Descending { $_.properties.CreationTime } | Select-Object name
az storage blob download --file $json[0].name --name $json[0].name --container-name $container_name_input --connection-string $sg_con_string
trigger:
- none
pr: none
pool:
vmImage: ubuntu-latest
variables:
- group: token-group
trigger:
- none
pr: none
parameters:
- name: containerlist
type: object
default: ["core/image1","core/image2","core/image3","core/image4"]
using System;
using System.Threading.Tasks;
using System.Configuration;
using System.Collections.Generic;
using System.Net;
using System.Timers;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
using System.IO;