Salesforce Backup Script – Automatisierung des Dump Downloads

Salesforce Backup Script – Automatisierung des Dump Downloads

Admins die in Ihrer Firma Salesforce einführen wollen bzw. schon einsetzen werden sicher irgendwann an dem Punkt stehen dass der von Salesforce vorgesehene Backup Prozess etwas…vorsichtig ausgedrückt “bescheiden” ist.
Um zumindest den Download des Dumps zu Automatisieren, habe ich ein Powershell Script geschrieben das mit unterstüztung der Software FuseIT SFDC Explorer den Dump auf das Lokale Backup Storage speichert.

Zuerst benötigen wird den FuseIT SFDC Explorer.
Download – Einen Dank an dieser Stelle an das Team von FuseIT die das kleine geniale Stück Software Kostenlos zur Verfügung stellen!
Dieser wird standardmäßig auf der Maschine installiert die das PowerShell Script am Schluss auch ausführt.

Zur ausführung meines Nachfolgenden Scripts wird PowerShell 2.0 benötigt!

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
#Salesforce FuseIT Backup Script by Michael Reischl http://www.gamorz.de /-/ V.0.2
#PowerShell 2.0 is needed!
#This Script uses FuseIT SFDC Explorer to get the Scheduled Salesforce DB Dumps.
#Download and Install FuseIT SFDC Explorer under http://www.fuseit.com/DownloadForm.aspx
#You can Automate the Salesforce Backup Process to be sure that every Week your Backup is saved to your local Storage
#Salesforce Dumps older than 30 Days got deleted in Standard Setting
#Base Informations
$fuseit = 'c:\Program Files (x86)\FuseIT\FuseIT SFDC Explorer\FuseIT.SFDC.DataExportConsole.exe' #Path to FuseIT Data Export Console Executable
$date = Get-Date -Format dddd.d.MM.yyyy #Get the Date in a easy Readable Form.
$time = Get-Date -uFormat %T #Get Time when Backup Starts
$week = Get-Date -uFormat %V #Get Week Number
$destbackup = "X:\\salesforce\$week" #Backup Destination Folder with Week Number
$destbackupmk = "X:\salesforce" #Backup Folder for creating Week Number Folders and Deleting old Images
$Logfile = "C:\Program Files (x86)\FuseIT\FuseIT SFDC Explorer\logs.txt" #Log File Path
$EmailFrom = "[email protected]" #Summary Email Sender Address
$EmailTo = "[email protected]" #Summary Email Receiver
$EmailSubject = "Salesforce DB Dump" #Summary Email Subject
$SMTPServer = "192.168.0.1" #Mail Server Address
$delold = "1" #Delete Salesforce Dumps older than 30 Days, set to 0 if you want to keep it.
#Salesforce Login Informations
$user = "[email protected]" #Salesforce User that have Access to the Dump Fule
$password = "my_password" #Salesforce Password
$stoken = "my_salesforce_token" #Salesforce Security Token
$env = "Production" #Salesforce Envoirement / Production / Sandbox / DeveloperEdition / Pre_release
#Create the Backup Destination Folder Based on Week Number, if the folder exists go further.
if (!(Test-Path -path $destbackupmk\$week))
{
New-Item $destbackupmk\$week -type directory
}
#Start FuseIT Data Export with the PreDefined Vars
& $fuseit /u:$user /p:$password /t:$stoken /e:$env $destbackup
#New Mail Sending on Powershell v2
$body = Get-Content $Logfile | Out-String
Send-MailMessage -SmtpServer $SMTPServer -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $body -Attachments $Logfile
#Check if there are Images older than 2 Weeks and Delete it
if ($delold -eq 1) {$Today = Get-Date
Get-Childitem $destbackupmk -recurse | Where-Object {($Today - $_.LastWriteTime).Days -gt 30} | Remove-Item -recurse}

Download PowerShell Salesforce Backup Script

Sobald die Variablen angepasst sind, kann das PowerShell Script ausgeführt und in die Aufgabenplanung des Backup Servers aufgenommen werden.
Das Dumpfile wird dann pro KW in einen eigenen Ordner gelegt und eine E-Mail mit dem Inhalt der Log Datei versandt.

Viel Spaß mit Salesforce und geruhsamen nächten dank des Backups ;-)


wallpaper-1019588
Die Algarve feiert 50 Jahre Nelkenrevolution
wallpaper-1019588
Mobile Suit Gundam SEED FREEDOM: Bandai Namco zeigt den Film in den deutschen Kinos
wallpaper-1019588
[Manga] Demon Slayer [2]
wallpaper-1019588
Soundtrack einer Generation: Musik und visuelle Medien harmonisieren