Jump to content

Backup auf SD bei SwyxExpress bzw. Max Version


Mathew

Recommended Posts

  • Most Valued User

Hallo,

ich brauchte für einen Kollegen ein Script das bei einer SwyxExpress bzw. Netphone Max ein Backup erstellt falls eine SD Karte vorhanden ist.

Daraus ist folgendes Script entstanden. Vielleicht kann es einer mal gebrauchen bzw. Teile davon für etwas anderes gebrauchen.

Mit einer kleinen Änderung funktioniert auch ein Backup auf einem Netzlaufwerk.

 

# Prüfung ob eine SD für ein Backup vorhanden ist (Max Version oder SwyxExpress)

# Welches Laufwerk soll geprüft werden?
$LW = "D:"

# Backup Ordner auf der SD
$SDZIEL = "D:\Backup" 

# Prüfe Laufwerk 
Write-Host
$SD = (Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DeviceID -eq "D:"})
switch ($SD.DriveType)
   {
		"2" {Write-Host "Laufwerk $LW ist ein Wechseldatentraeger (SD)"}
		"3" {Write-Host "Laufwerk $LW ist eine Festplatte"}
		"4" {Write-Host "Laufwerk $LW ist ein Netzlaufwerk"}
		"5" {Write-Host "Laufwerk $LW ist ein CDROM bzw. DVDROM"}
		default {Write-Host "Laufwerk $LW ist nicht vorhanden"}
	}
	
# Wenn $LW eine Wechseldatenträger ist erzeuge ein Backup
if ($SD.DriveType -eq 2)
	{	
	
		# Ist es eine Swyxware oder Netphone		
		$swyxPath = "C:\Program Files (x86)\SwyxWare"
		$tcomPath = "C:\Program Files (x86)\Netphone"
		
		Write-Host "Suche nach einer IpPbx Installation."
		    
			if (Test-Path -Path $swyxPath)
				{
					Write-Host "Eine SwyxWare Installation gefunden."
					$SERVERVERSION = $swyxPath
				}	
			elseif (Test-Path -Path $tcomPath)
				{
					Write-Host "Eine NetPhone Installation gefunden."
					$SERVERVERSION = $tcomPath
				}
			else
				{
					Write-Host -foregroundcolor red "Keine IpPbx Installation gefunden! Script wird beendet."
					pause
					break
				}
	
	
		# Prüfe ob der Ordner für unser backup existiert, sonst neu erstellen
		if (-Not(Test-Path $SDZIEL)) 
			{
				Write-Host -foregroundcolor yellow "Ordner $($SSDZIEL) existiert noch nicht, lege ihn an..."
			
				New-Item -ItemType Directory -Force -Path $SSDZIEL
			}
		# Datum in deutsch
		$Datum = (Get-Date).ToString('MM-dd-yyyy')
		
		# Uhrzeit in deutsch
		$Uhrzeit = (get-date).ToLongTimeString() | foreach {$_ -replace ":", "-"}

		# Befehl um das Backup zu erzeugen
		$Command = "$SERVERVERSION\IpPbxConfig.exe"
		$Parms = "/backup -file $SDZIEL\IpPbxBackup-$Datum-$Uhrzeit.dat"
		$Prms = $Parms.Split(" ")
		& "$Command" $Prms
		
		Write-Host "Backup auf SD geschrieben."
		}
else 
	{
	Write-Host -foregroundcolor red "Kein Backup geschrieben! Laufwerk $LW ist kein Wechseldatentraeger."
	Write-Host
	}
	

 

Gruß

Mathew

 

 

Link to comment
Share on other sites


Hallo @Mathew

 

Vielen Dank!

 

Hier habe ich noch eins, welches das Backup zusätzlich auf einen FTP Server ablegt.


 

# Admin Richtlinien
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
# Admin Richtlinien Ende

# Datum
$date = Get-Date -Format yyyyMMddHHmmss

# Datenbankname
$dbname = 'IpPbx'

# Swyxserver
$Servername = 'xxx'

# Verzeichnise
$Dir1 = "C:\BACKUP\SWYXDB"

$DBfile = Get-ChildItem "$Dir1" | sort LastWriteTime -desc | select -First (1)

# Ort der Datenbank und Speicherort des Backups und Anzahl Backups (skip)
Backup-SqlDatabase -ServerInstance $Servername\SQLEXPRESS  -Database $dbname -BackupFile "$Dir1\$($dbname)_db_$($date).dat"
dir "$Dir1" | ? {!$_.psiscontainer} | sort LastWriteTime -desc | select -skip(10) | del

# FTP Server
$ftp = "ftp://server/Pfad/xxx/xx"
$user = "xxx"
$pass = "xxx"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
$uri = New-Object System.Uri("$ftp/$($DBfile.Name)")

"Uploading $DBfile..."
$webclient.UploadFile($uri, $DBfile.FullName)

Grüsse

Remo

Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.