Scheduled Backup

Auflistung von gewünschten Features, Ausschreibung zur Umsetzung
yankee
Beiträge: 481
Registriert: Sa Mai 16, 2020 11:34 am

Re: Scheduled Backup

Beitrag von yankee »

slankes hat geschrieben: Sa Jan 02, 2021 3:52 pm Das hier funktioniert bei mir:

Code: Alles auswählen

[..]curl -sS -o $OUTPUTDIR/openwb-backup-$(date +%Y%M%d).tar.gz[..]
Statt `%M` war hier bestimmt `%m` eher gedacht:

Code: Alles auswählen

%m     month (01..12)
%M     minute (00..59)
Aber sonst ja, funktioniert hevorragend.

Ich habe für mich das Skript wie folgt angepasst:

Code: Alles auswählen

BACKUP_DIR=/volumeX/SHARE/SOME/PATH
curl -sS -o "$BACKUP_DIR"/openwb-backup-$(date +%Y%m%d).tar.gz http://DOMAIN_OR_IP_OF_OPEN_WB/openWB/web/backup/backup.tar.gz
ls "$BACKUP_DIR"/openwb-backup-* | head -n -7 | xargs -d '\n' rm
Die letzte Zeile bewirkt, dass wenn mehr als 7 Backups vorhanden sind, dann werden die ältesten Backups gelöscht, so dass nurnoch 7 Backups da sind.

Anleitung für Anfänger die das (so wie ich) auf eine Synology DiskStation nutzen wollen (ich habe meine DiskStation auf Englisch, aber ich denke es sollte auffindbar sein):

In der Diskstation auf "Control Panel > Task Scheduler > Create > Scheduled Task > User-defined script". Dann im Tab "Task Setting" Unter "Run command" einfach den obigen Code reinkopieren und noch den Pfad hinter `BACKUP_DIR=` anpassen und DOMAIN_OR_IP_OF_OPEN_WB ersetzen. Unter "Schedule" noch angeben, wann man möchte, dass das ausgeführt wird.

Man mag geneigt sein unter "Schedule" eine Uhrzeit nachts anzugeben, weil da ja nichts los ist. Allerdings befindet sich da die DiskStation, weil ja gerade nichts los ist, vielleicht auch gerade im Schlafmodus (insbesondere relevant wenn noch diese altmodischen rotierenden Festplatten drin sind) und dann will man die dafür nicht unbedingt extra aufwecken ;-)). Insofern mag eine Zeit tagsüber sinnvoller sein.
burningbecks
Beiträge: 29
Registriert: Mo Nov 09, 2020 5:41 pm
Kontaktdaten:

Re: Scheduled Backup

Beitrag von burningbecks »

mrinas hat geschrieben: Fr Jan 08, 2021 4:23 pm So, das hier klappt nun und verwendet den Link welchen die openWB beim Aufruf der backup.php liefert.

Ich starte das über die Aufgabenplanung auf meinem PC einmal monatlich. Im Reiter Bedingungen noch den Haken bei 'Beenden, wenn Computer in Akkubetrieb wechselt' entfernen und dafür in 'Einstellungen' den Haken bei 'Aufgabe so schnell wie möglich nach einem verpassten Start ausführen' setzen - dann wird das auch durchgeführt wenn zum Zeitpunkt des geplanten Backups der Rechner gerade nicht läuft.

Ausgeführt wird "powershell.exe" mit diesen Parametern: "-ExecutionPolicy Bypass C:\Users\martrin\OneDrive\openWB\Get-OpenWBBackup.ps1" Wobei der Pfad & Name zum Script natürlich noch auf die eigene Umgebung angepasst werden muss.

Code: Alles auswählen

# Environmental parameters
$OpenWBIP = '192.168.178.51'
$LocalBackupFolder = "$Env:UserProfile" + '\Documents\'

# Generate backup file name, change optional
$LocalBackupFileName = ("OpenWB-backup-" + (get-date -format u) + ".tar.gz").Replace(":","-")
$LocalBackupPath = $LocalBackupFolder + $LocalBackupFileName

# Path definitions, no need to change them unless openWB changes location of those files
$OpenWBBackupPath = '/openWB/web/tools/backup.php'
$URIToCall = "http://" + $OpenWBIP + $OpenWBBackupPath

$Result = Invoke-WebRequest -uri $URIToCall #create backup

if ($Result.StatusCode -eq '200') # New backup created?
{
    try 
    {
        #$OpenWBBackupDownloadPath = '/openWB/web/backup/backup.tar.gz' # We could also use $Result.Links.href to dynamically fetch location if we wanted to. Does require extra handling if more than one link is provided
        if ($Result.Links.Count -gt 1)
        {
            throw "More than one link found in response, cannot proceed."
        }
        $OpenWBBackupDownloadPath = $Result.Links.href
        $BackupURI = "http://" + $OpenWBIP + $OpenWBBackupDownloadPath
        Invoke-WebRequest -Uri $BackupURI -OutFile $LocalBackupPath # Downlaod backup and store locally
        Write-Host "Created backup at $LocalBackupPath" # we're done here
    }  
    catch 
    {
        Write-Host "Backup created but couldn't be downloaded." 
    }
}
else 
{
    Write-Host 'Unexpected return code when asking for backup:' ($Result.StatusCode) ($Result.StatusDescription)   
}
Perfekt - danke, mrinas! :)
BMW i3s, go-eCharger Gemini (22kW FIX).
openWB Standalone + EVU Kit v2 MID als Lastmanager.
Benutzeravatar
mrinas
Beiträge: 1867
Registriert: Mi Jan 29, 2020 10:12 pm

Re: Scheduled Backup

Beitrag von mrinas »

burningbecks hat geschrieben: So Mai 30, 2021 1:44 pm
mrinas hat geschrieben: Fr Jan 08, 2021 4:23 pm So, das hier klappt nun und verwendet den Link welchen die openWB beim Aufruf der backup.php liefert.

Ich starte das über die Aufgabenplanung auf meinem PC einmal monatlich. Im Reiter Bedingungen noch den Haken bei 'Beenden, wenn Computer in Akkubetrieb wechselt' entfernen und dafür in 'Einstellungen' den Haken bei 'Aufgabe so schnell wie möglich nach einem verpassten Start ausführen' setzen - dann wird das auch durchgeführt wenn zum Zeitpunkt des geplanten Backups der Rechner gerade nicht läuft.

Ausgeführt wird "powershell.exe" mit diesen Parametern: "-ExecutionPolicy Bypass C:\Users\martrin\OneDrive\openWB\Get-OpenWBBackup.ps1" Wobei der Pfad & Name zum Script natürlich noch auf die eigene Umgebung angepasst werden muss.

Code: Alles auswählen

# Environmental parameters
$OpenWBIP = '192.168.178.51'
$LocalBackupFolder = "$Env:UserProfile" + '\Documents\'

# Generate backup file name, change optional
$LocalBackupFileName = ("OpenWB-backup-" + (get-date -format u) + ".tar.gz").Replace(":","-")
$LocalBackupPath = $LocalBackupFolder + $LocalBackupFileName

# Path definitions, no need to change them unless openWB changes location of those files
$OpenWBBackupPath = '/openWB/web/tools/backup.php'
$URIToCall = "http://" + $OpenWBIP + $OpenWBBackupPath

$Result = Invoke-WebRequest -uri $URIToCall #create backup

if ($Result.StatusCode -eq '200') # New backup created?
{
    try 
    {
        #$OpenWBBackupDownloadPath = '/openWB/web/backup/backup.tar.gz' # We could also use $Result.Links.href to dynamically fetch location if we wanted to. Does require extra handling if more than one link is provided
        if ($Result.Links.Count -gt 1)
        {
            throw "More than one link found in response, cannot proceed."
        }
        $OpenWBBackupDownloadPath = $Result.Links.href
        $BackupURI = "http://" + $OpenWBIP + $OpenWBBackupDownloadPath
        Invoke-WebRequest -Uri $BackupURI -OutFile $LocalBackupPath # Downlaod backup and store locally
        Write-Host "Created backup at $LocalBackupPath" # we're done here
    }  
    catch 
    {
        Write-Host "Backup created but couldn't be downloaded." 
    }
}
else 
{
    Write-Host 'Unexpected return code when asking for backup:' ($Result.StatusCode) ($Result.StatusDescription)   
}
Perfekt - danke, mrinas! :)
da fällt mir ein, ich hatte ja noch eine neuere Version des Scripts erstellt. Diese Variante erstellt auch den geplanten Task und hatte noch ein paar andere Anpassungen. Muss das mal per PR einstellen, derweil hier schonmal meine aktuelle Version.


Einfach im Pfad der Wahl als Get-OpenWBBackup.ps1 abspeichern und abrufen. Ohne weitere Parameter wird nach der IP der openWB gefragt und ein geplanter Task erstellt. get-help get-openwbbackup liefert weitere Details was das Script noch so machen kann.

Code: Alles auswählen

  
<#
  .SYNOPSIS
  Creates ad-hoc and scheduled backup of openWB wallbox.
  .DESCRIPTION
    This script will create a backup of the openWB wallbox and store the backup in a folder while keeping older versions. The script can also register a scheduled task to automate the backup creation. 
    Starting the script without any parameters will 1) ask for the IP of the openWB, 2) check if a scheduled task already exists. A new task will be registered if needed and an immediate backup will be created. Script will not perform any action if backup job already exists. 
    Start script with -RunOnce parameter to perform an immediate backup without creating the scheduled task.
  .PARAMETER LocalBackupFolder
  Specifies local path to store backups. Defaults to script location
  .PARAMETER OpenWBIP
  IP of openWB, required parameter.
  .PARAMETER VerboseLogFileName
  Logfile for Verbose output, defaults to VerboseOutput.Log if not specified
  .PARAMETER AppendToLogfile
  Appends to existing verbose log file, defaults to override.
  .PARAMETER RunOnce
  Execute backup directly, skip creation of scheduled task.
    .EXAMPLE
  PS> .\Get-OpenWBBackup.ps1
  Checks for scheduled task, creates one if it doesn't exist already. openWB backup will be executed every 4 weeks, Monday at 09:00 local time. Reruns if time is missed. After creating the task an immediate backup is created. 
  Skips all actions if a scheduled task already exists.
  .EXAMPLE
  PS> .\Get-OpenWBBackup.ps1 -OpenWBIP 192.168.178.200 -RunOnce
  Performs an immediate backup of OpenWB 192.168.178.200 and skips creation of scheduled task.
  
  .NOTES
  MIT License
  Copyright (c) 2021 Martin Rinas
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
#>
[CmdletBinding()] #few examples how a script accepts input parameters
param
(
    [Parameter(Mandatory=$false)]
    [ValidateScript({Test-Path $_ })]
    [string]$LocalBackupFolder,
    [Parameter(Mandatory=$true,HelpMessage="Please enter IP of openWB")]
    [string]$OpenWBIP,
    [Parameter(Mandatory=$false)]
    [string] $VerboseLogFileName = 'VerboseOutput.Log',
    [switch]$AppendToLogfile,
    [switch]$RunOnce
)



#region function definition
function Write-VerboseLog{
    <#
        .SYNOPSIS
        Writes messages to Verbose output and Verbose log file
        .DESCRIPTION
        This fuction will direct verbose output to the console if the -Verbose 
        paramerter is specified.  It will also write output to the Verboselog.
        .EXAMPLE
        Write-VerboseLog -Message 'This is a single verbose message'
        .EXAMPLE
        # Write-VerboseLog -Message ('This is a more complex version where we want to include the value of a variable: {0}' -f ($MyVariable | Out-String) )
    #>
    param(
      [String]$Message  
    )
  
    $VerboseMessage = ('{0} Line:{1} {2}' -f (Get-Date), $MyInvocation.ScriptLineNumber, $Message)
    Write-Verbose -Message $VerboseMessage
    Add-Content -Path $VerboseLogFileName -Value $VerboseMessage
  }
function Register-OpenWBBackupTask
{
    param
    (
        [Parameter(Mandatory=$true,HelpMessage='Full path to the backup script')]
        [ValidateScript({Test-Path $_ })]
        [String]$ScriptPath,
        [Parameter(Mandatory=$true,HelpMessage='Name of backuptask')]
        [string]$TaskName,
        [Parameter(Mandatory=$true,HelpMessage='IP of OpenWB')]
        [string]$IPAddr

    )
    try 
    {
        $null = Get-ScheduledTask -TaskName $TaskName -ErrorAction stop
        Write-VerboseLog -Message ('Scheduled Task: {0} does already exist. Please delete first if you want to re-create' -f ($TaskName | Out-String) )
        Write-Error "Task $TaskName already exists. Will not re-create, please delete manually in Task Scheduler if you want to re-create. Exiting."
        break
    }
    catch 
    {
        # Scheduled Task does not exist. Creating.
        Write-VerboseLog -Message ('Scheduled task: {0} does not exist, creating.'-f ($TaskName | Out-String) )
        $WorkingDir = Split-Path $ScriptPath -Parent
        Write-VerboseLog -Message ('Setting Working directory to: {0}' -f($WorkingDir | out-string))
        $Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy Bypass -File  `"$ScriptPath`" -RunOnce -openWBIP $IPAddr" -WorkingDirectory $WorkingDir
        $Trigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 4 -At '09:00' -DaysOfWeek Monday
        $Principal = New-ScheduledTaskPrincipal -LogonType Interactive -Id Author -UserId $env:USERNAME -RunLevel Limited -ProcessTokenSidType Default
        $Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 1) -StartWhenAvailable -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
        $ScheduledTask = New-ScheduledTask -Action $Action -Principal $Principal -Settings $Settings -Trigger $Trigger -Description 'OpenWB BackupJob'
        Register-ScheduledTask $TaskName -InputObject $ScheduledTask -ErrorAction Stop
    }

}

#endregion

#region variable definition
if ([string]::IsNullOrEmpty($LocalBackupFolder))
{
    $LocalBackupFolder = (Split-path $MyInvocation.MyCommand.Path -parent)
    Write-VerboseLog -Message ('LocalBackupFolder was empty, set to {0}' -f ($LocalBackupFolder))
}

if([string]::IsNullOrEmpty($ScriptLocation))
{
    $ScriptLocation = (Split-path $MyInvocation.MyCommand.Path -parent)
    Write-VerboseLog -Message ('ScriptLocation was empty, set to {0}' -f ($ScriptLocation))
}

$LocalBackupFileName = ("OpenWB-backup-" + (get-date -format u) + ".tar.gz").Replace(":","-")
$LocalBackupPath = $LocalBackupFolder + '\' + $LocalBackupFileName
$OpenWBBackupPath = '/openWB/web/settings/backup.php'
$URIToCall = "http://" + $OpenWBIP + $OpenWBBackupPath
$BackupTaskName = 'openWB Backup'
$ScriptName = $MyInvocation.MyCommand

#endregion

#region main script
if (!$AppendToLogfile)
{
    $null = New-Item -Path $VerboseLogFileName -ItemType File -Force
    Write-VerboseLog -Message 'Script started'
    Write-VerboseLog -Message ('Parameters: {0}' -f ($MyInvocation | Out-String) )
}
else 
{
    Write-VerboseLog -Message 'Script started, appending to existing log'
}

if ($RunOnce)
{
    Write-VerboseLog 'Skip scheduled task and executy directly'
}
else
{
    # check for and create scheduled task
    Write-VerboseLog -message ('Checking for existence of scheduled task: {0} and creating if needed. ' -f ($BackupTaskName) )
    
    try 
    {
        $null = Get-ScheduledTask -TaskName $BackupTaskName -ErrorAction stop
        Write-VerboseLog -Message ('Scheduled Task: {0} does already exist. ' -f ($BackupTaskName) )
        $BackupTaskExists = $True
    }
    catch 
    {
        Write-VerboseLog -Message ('Scheduled Task: {0} does not exist. ' -f ($BackupTaskName) )
        $BackupTaskExists = $False
    }

    if ($BackupTaskExists)
    {
        Write-VerboseLog -Message ('nothing to do.' -f ($BackupTaskName) )
        Write-Host "Backupjob $BackupTaskName already exists, nothing to do. Exiting..."
        exit
    }
    else
    {
        Write-VerboseLog -Message ('BackupTask: {0} does not already exist, creating.' -f ($BackupTaskName) )    
        Write-Host "Creating scheduled backup task for openWB"
        $FullScriptPath = $ScriptLocation + '\' + $ScriptName
        Write-VerboseLog -Message ('Full script location: {0}' -f ($FullScriptPath| Out-String))
        Register-OpenWBBackupTask -TaskName $BackupTaskName -ScriptPath $FullScriptPath -IPAddr $OpenWBIP
        Write-Host "Creating one backup immediately."
    }
}

Write-VerboseLog -Message ('Using this as backup path to store file: {0}' -f ($LocalBackupPath | Out-String) )

Write-Host "Starting backup of openWB"
Write-VerboseLog -Message ('Triggering openWB backup creation by calling: {0}' -f ($URIToCall | Out-String) )
$Result = Invoke-WebRequest -uri $URIToCall -UseBasicParsing  #create backup

if ($Result.StatusCode -eq '200') # New backup created?
{
    try 
    {
        #$OpenWBBackupDownloadPath = '/openWB/web/backup/backup.tar.gz' # We could also use $Result.Links.href to dynamically fetch location if we wanted to. Does require extra handling if more than one link is provided
        if ($Result.Links.Count -gt 1)
        {
            Write-VerboseLog -Message ('More than one link found in response: {0}' -f ($result.links | Out-String) )
            throw "More than one link found in response, cannot proceed."
        }
        $OpenWBBackupDownloadPath = $Result.Links.href
        $BackupURI = "http://" + $OpenWBIP + $OpenWBBackupDownloadPath
        Write-VerboseLog -Message ( 'Backup generated, downloading from: {0} to : {1}' -f ($BackupURI | Out-String), ($LocalBackupPath | Out-String) )
        Invoke-WebRequest -Uri $BackupURI -OutFile $LocalBackupPath # Downlaod backup and store locally
        Write-Host "Created backup at $LocalBackupPath" # we're done here
        Write-VerboseLog -Message 'Download completed.'
    }  
    catch 
    {
        Write-VerboseLog 'Backup created bout could not be downloaded'
        Write-Host "Backup created but couldn't be downloaded." 
    }
}
else 
{
    Write-VerboseLog -Message ( 'Unexpected return code when asking for backup: {0} {1}' -f ($result.StatusCode | Out-String), ($Result.StatusDescription | Out-String ) )
    Write-Host 'Unexpected return code when asking for backup:' ($Result.StatusCode) ($Result.StatusDescription)   
}
#endregion
15,2kWp SMA (SB4000TL-21, SB3.0, STP6.0-SE + BYD HVS, EnergyMeter), openWB Standard+, openWB Pro, Peugeot e2008, Tesla Model Y LR.
FosCo
Beiträge: 185
Registriert: Di Jun 30, 2020 9:26 am

Re: Scheduled Backup

Beitrag von FosCo »

Ich wünsche mir da ein Push, da ich keinen ssh Zugang habe (Support)
17kWp Ost/Süd/West, Kostal PIKO 17, (noch) Discovergy, 2x openWB series 2 custom, FHEM, Proxmox mit OpenWB 2.x und am Basteln
Benutzeravatar
mrinas
Beiträge: 1867
Registriert: Mi Jan 29, 2020 10:12 pm

Re: Scheduled Backup

Beitrag von mrinas »

FosCo hat geschrieben: Mo Mai 31, 2021 6:31 am Ich wünsche mir da ein Push, da ich keinen ssh Zugang habe (Support)
Ich habe auf meine produktiv genutzte Box auch kein SSH Zugang, mein PowerShell Script wird auf einem beliebigen Windows-Rechner gestartet. Dieser führt dann das regelmässige Backup durch. Verpasste Wiederholungen, z.b. weil der Rechner gerade aus war, werden nachgeholt.
15,2kWp SMA (SB4000TL-21, SB3.0, STP6.0-SE + BYD HVS, EnergyMeter), openWB Standard+, openWB Pro, Peugeot e2008, Tesla Model Y LR.
FosCo
Beiträge: 185
Registriert: Di Jun 30, 2020 9:26 am

Re: Scheduled Backup

Beitrag von FosCo »

mrinas hat geschrieben: Mo Mai 31, 2021 6:54 am
FosCo hat geschrieben: Mo Mai 31, 2021 6:31 am Ich wünsche mir da ein Push, da ich keinen ssh Zugang habe (Support)
Ich habe auf meine produktiv genutzte Box auch kein SSH Zugang, mein PowerShell Script wird auf einem beliebigen Windows-Rechner gestartet. Dieser führt dann das regelmässige Backup durch. Verpasste Wiederholungen, z.b. weil der Rechner gerade aus war, werden nachgeholt.
Oh ok, zu schnell geschaut dann, danke!

Edit: erst lesen, dann posten, schreiendes Baby lenkt etwas ab 😂
Zuletzt geändert von FosCo am Mo Mai 31, 2021 7:00 am, insgesamt 1-mal geändert.
17kWp Ost/Süd/West, Kostal PIKO 17, (noch) Discovergy, 2x openWB series 2 custom, FHEM, Proxmox mit OpenWB 2.x und am Basteln
Benutzeravatar
mrinas
Beiträge: 1867
Registriert: Mi Jan 29, 2020 10:12 pm

Re: Scheduled Backup

Beitrag von mrinas »

FosCo hat geschrieben: Mo Mai 31, 2021 6:58 am
mrinas hat geschrieben: Mo Mai 31, 2021 6:54 am
FosCo hat geschrieben: Mo Mai 31, 2021 6:31 am Ich wünsche mir da ein Push, da ich keinen ssh Zugang habe (Support)
Ich habe auf meine produktiv genutzte Box auch kein SSH Zugang, mein PowerShell Script wird auf einem beliebigen Windows-Rechner gestartet. Dieser führt dann das regelmässige Backup durch. Verpasste Wiederholungen, z.b. weil der Rechner gerade aus war, werden nachgeholt.
Oh ok, zu schnell geschaut dann, danke!

Muss ich dann mal auf der Windows Büchse testen.
Dauerhaft läuft nur Linux und FreeBSD bei mir, muss ich mich mal dran versuchen, danke auf jeden Fall!
Hier im Thread gabs auch eine Linux/Unix Variante für ein Backup-Script. Mein Windowsrechner läuft auch nicht immer sondern nur tagsüber wenn ich arbeite, bisher tut das Backup hier einwandfrei.
15,2kWp SMA (SB4000TL-21, SB3.0, STP6.0-SE + BYD HVS, EnergyMeter), openWB Standard+, openWB Pro, Peugeot e2008, Tesla Model Y LR.
Jaschkopf
Beiträge: 2
Registriert: Sa Jul 31, 2021 4:35 pm

Re: Scheduled Backup

Beitrag von Jaschkopf »

Servus,

ich habe gerade das Skript auf meiner Synology als Schedule angelegt. Es wird dann jedoch nur eine 1kb große Datei angelegt. Kann mir jemand auf die Sprünge helfen woran das liegen könnte?

Gruß Jascha
Jaschkopf
Beiträge: 2
Registriert: Sa Jul 31, 2021 4:35 pm

Re: Scheduled Backup

Beitrag von Jaschkopf »

Ich hab das PRoblem gerade selbst gefunden. Die URL hat sich scheinbar geändert, von /openWB/web/tools/backup.php zu /openWB/web/settings/backup.php

Mein Skript sieht jetzt so aus:

Code: Alles auswählen

#!/bin/bash
WALLBOXBASEURL=http://123.123.123.123
OUTPUTDIR=/volume1/backup/Smarthome/openWB_Wallbox

curl -sS -o /dev/null $WALLBOXBASEURL/openWB/web/settings/backup.php
if [ $? -eq 0 ]
then
  curl -sS -o $OUTPUTDIR/openWB_backup_$(date +%Y-%m-%d_%H-%M-%S).tar.gz $WALLBOXBASEURL/openWB/web/backup/backup.tar.gz
ls "$OUTPUTDIR"/openWB_backup_* | head -n -10 | xargs -d '\n' rm
else
  echo "Failed to create backup"
fi
Ich habe noch die auto-delete Funktion von @yankee mit eingebaut. Das Skript läuft 1x pro Woche und es werden die letzten 10 Backups behalten

Gruß Jascha
QuisaZaderak
Beiträge: 10
Registriert: Mi Dez 02, 2020 6:18 pm

Re: Scheduled Backup

Beitrag von QuisaZaderak »

Falls jemand auch so wie ich seine OpenWB mit Passwort geschützt hat dann bitte Zeile 197 wie folgt ergänzen:

Code: Alles auswählen

$Result = Invoke-WebRequest -uri $URIToCall -UseBasicParsing -Credential $credential  #create backup
Und am besten ab Zeile 140 folgendes einfügen:

Code: Alles auswählen

$user = "username"
$pass = "password"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
Da ich zwei OpenWBs habe, habe ich auch noch folgende Zeilen angepasst:
Zeile 134:

Code: Alles auswählen

$LocalBackupFileName = ("OpenWB-backup-" + $OpenWBIP.Replace(".","-") + "-" + (get-date -format u) + ".tar.gz").Replace(":","-")
Zeile 138:

Code: Alles auswählen

$BackupTaskName = "openWB Backup "+ $OpenWBIP
Zeile 195 (original) bzw. 199 (mit credential):

Code: Alles auswählen

Write-Host "Starting backup of openWB" $OpenWBIP
Grüße Manuel
2x openWB series2 standard+ 11kW | 4,83 kWp PV | Kia EV6 GT (ehem Audi e-tron 55)
Antworten