-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_backup.ps1
38 lines (29 loc) · 1.1 KB
/
git_backup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
param (
[string]$configName
)
$config = Get-Content -Path (".\$configName\"+"$configName"+".json") | ConvertFrom-Json
$commandPath = $PSCommandPath | Split-Path -Parent
Import-Module (".\$configName\"+"$configName"+".psm1") -Force
$pair = "$($config.username):$($config.password)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = 'Basic '+$encodedCredentials
$folderName = Get-Date -Format "MMddyyyy-HH-mm"
md $commandPath/$folderName
Set-Location $commandPath/$folderName
$size = 1
$pagelen = 100
For ($i=1; $i -le $size; $i++) {
$params = @{
Uri = ($config.apiurl + "$i")
Headers = @{ 'Authorization' = $basicAuthValue }
Method = 'GET'
Body = $jsonSample
ContentType = 'application/json'
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$response = Invoke-RestMethod @params
if($response.size) {
$size = [int][Math]::Ceiling($response.size / $pagelen)
}
GitClone -config $config -response $response
}