-
Notifications
You must be signed in to change notification settings - Fork 0
/
Docker-Restore.ps1
78 lines (69 loc) · 2.09 KB
/
Docker-Restore.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
### Powershell script for Restoring Docker containers from backup ZIPs
### Parameters ##
param
(
[parameter(Mandatory=$True)]
[String] $Server,
[parameter(Mandatory=$True)]
[String] $Share,
[String] $type = "nfs",
[String]$filename = $Null,
[parameter(Dontshow)]
[String] $Username = $Null,
[parameter(Dontshow)]
[String] $Password = $Null,
[parameter(Dontshow)]
[String] $Domain = $Null
)
### Functions
function LOG-Event
{
param (
[string]$MSG,
[string]$Color = "yellow"
)
$TimeStamp = (Get-Date).ToString("hh:mm:sstt")
$OUTMSG = "[$TimeStamp] - " + $MSG
write-host $OUTMSG -ForegroundColor $Color
Add-content $LogFile -value $OUTMSG
}
# Global Log File
$Global:LogPath = "/var/log/docker-backup/"
$Global:LogFile = $LogPath + "DockerBackup.log"
#$Global:LogFile = $LogPath + "DockerBackup_" + (Get-Date).ToString("MMddyyyy_hhmmsstt") + ".log"
if(!(Test-Path $LogPath)){New-Item -ItemType directory $LogPath}
# Default Variables
$ScriptDir = (Get-Location).Path
$CredFile=$ScriptDir+"/.credential"
$mount="/mnt/backup"
$srcloc=$mount + "/config-backup/$(hostname)/"
$fileloc=$srcloc + $filename
If (!(Test-Path $mount)){
$MSG = "Creating Directory "+ $mount
LOG-Event $MSG
New-Item -ItemType directory $mount
}
switch($type.ToLower()) {
"smb" {
$Connect = $Server + $Share
$MSG = "Mounting SMB Share " + $Connect
LOG-Event $MSG
"username=$username" | out-file -Append -FilePath $credfile
"password=$password" | out-file -Append -FilePath $credfile
"domain=$domain" | out-file -Append -FilePath $credfile
mount -t cifs -o credentials=$CredFile $Connect $mount
remove-item $CredFile -force
}
default {
$MSG = "Mounting NFS Share " + $server + ":" + $Share
LOG-Event $MSG
mount -t nfs $server":"$Share $mount
}
}
$MSG = "Restoring Backup " + $filename
LOG-Event $MSG
unzip $fileloc
#unmount backup loc
$MSG = "Unmounting Backup Destination.<Operation completed>"
LOG-Event $MSG
umount $mount