From 7fc74081d3f7d7d487c61fb18fce559770351e16 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Lendholt Date: Fri, 1 Dec 2023 11:45:07 +0100 Subject: [PATCH 1/7] Added default parameters to openwb.conf handling the new backup feature --- openwb.conf | 7 ++ runs/cronnightly.sh | 15 ++++ web/settings/backup.php | 175 ++++++++++++++++++++++++++++++++-------- 3 files changed, 162 insertions(+), 35 deletions(-) diff --git a/openwb.conf b/openwb.conf index c5600b81c..2ea243ca8 100755 --- a/openwb.conf +++ b/openwb.conf @@ -270,3 +270,10 @@ soc_aiwayslp2_user='' soc_aiwayslp2_pass='' soc_aiwayslp2_vin='' soc_aiwayslp2_intervall='' +backuptarget=ftp +ftphost=192.168.170.1 +ftppath=/UBUNTU_20_0 +ftpuser=ftp +ftppass=bh220540 +nightlybackup=1 +shortbackupfilename=1 diff --git a/runs/cronnightly.sh b/runs/cronnightly.sh index d5779914b..b7ef5fc12 100755 --- a/runs/cronnightly.sh +++ b/runs/cronnightly.sh @@ -30,6 +30,7 @@ ll6=$(<"$RAMDISKDIR/llkwhlp6") # Zählerstand LP6 ll7=$(<"$RAMDISKDIR/llkwhlp7") # Zählerstand LP7 ll8=$(<"$RAMDISKDIR/llkwhlp8") # Zählerstand LP8 llg=$(<"$RAMDISKDIR/llkwhges") # Zählerstand Gesamt +ipaddr=$(<"$RAMDISKDIR/ipaddress") is_configured_cp1="1" #Ladepunkt 1 ist immer konfiguriert is_configured_cp2=$lastmanagement # LP2 konfiguriert? @@ -148,3 +149,17 @@ done # monthly . csv updaten echo "Trigger update of logfiles..." python3 /var/www/html/openWB/runs/csvcalc.py --input /var/www/html/openWB/web/logging/data/daily/ --output /var/www/html/openWB/web/logging/data/v001/ --partial /var/www/html/openWB/ramdisk/ --mode A >> /var/www/html/openWB/ramdisk/csvcalc.log 2>&1 & + +#check if backup is configured - if yes, let's go +if [[ $nightlybackup == 1 ]]; then + echo "Nightly backup turned on. Performing backup." + port=$WEB_PORT + if [[ -z "$port" ]]; then + port=80 + fi + url="http://127.0.0.1:$port/openWB/web/settings/savebackup.php?extendedFilename=$shortbackupfilename" + echo "Using url $url" + curl -s -o /dev/null $url +else + echo "Nightly backup turned off. Doing nothing." +fi \ No newline at end of file diff --git a/web/settings/backup.php b/web/settings/backup.php index 5d7e1699e..52eeac4ca 100644 --- a/web/settings/backup.php +++ b/web/settings/backup.php @@ -1,23 +1,3 @@ - @@ -26,9 +6,8 @@ - - Backup erstellen - + + openWB Einstellungen @@ -45,7 +24,6 @@ - @@ -53,44 +31,171 @@ - + + + + + +
- -

Backup erstellen

-
- Backup-Datei erfolgreich erstellt. +

OpenWB Backup

+
+
+
+ Backup-Ziel + +
+
+
+
+ +
+ +
+
+
+ +
+ + /> +
+
+
+ +
+ + /> + Wenn aktiviert, wird die Datei unter den Namen backup.tar.gz am Zielort abgelegt. Wenn nicht aktiviert, wird die Datei unter dem Muster "openWB_backup_$jahr-$monat-$tag-$hourofday-$minute.tar.gz" abgelegt (Beispiel: openWB_backup_2023-11-30_17-19-11.tar.gz) +
+
+
+
+
+
+
+ +
+ + Der FTP-Host als voller DNS-Name oder IP-Adresse +
+
+
+ +
+ + + Der Pfad auf dem Zielsystem, zB /Backups/openwb +
+
+
+
+
+ +
+ + Der Nutzername für das FTP-System +
+
+
+ +
+ + Das FTP-Passwort, gespeichert in der openwb.conf +
+
+ +
+
+ +
-
- Sie befinden sich hier: System/Backup erstellen + Sie befinden sich hier: System/Backup
From d3f2716bac291162e7bdf72e0bcf86bcdfc41c75 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Lendholt Date: Fri, 1 Dec 2023 11:46:29 +0100 Subject: [PATCH 2/7] moving backup logic to savesettings.php --- web/settings/savebackup.php | 161 ++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 web/settings/savebackup.php diff --git a/web/settings/savebackup.php b/web/settings/savebackup.php new file mode 100644 index 000000000..a71b1762a --- /dev/null +++ b/web/settings/savebackup.php @@ -0,0 +1,161 @@ +"; + $filename = buildBackup($useExtendedFilename, $backupPath); + echo ""; + echo ""; + ftpUpload($filename, $backupPath, $ftphostold, $ftppathold, $ftpuserold, $ftppassold); + } else { + echo ""; + $filename = buildBackup($useExtendedFilename, $backupPath); + echo ""; + } + + + function ftpUpload($filename, $backupPath, $host, $path, $user, $pass) { + $localfile = $backupPath.$filename; + $remotefile = $filename; + echo "Local file ".$localfile; + echo "Upload ".$remotefile; + + $ch = curl_init(); + $fp = fopen($localfile, 'r'); + curl_setopt($ch, CURLOPT_URL, "ftp://".$user.":".$pass."@".$host.":".$path."/".$filename); + curl_setopt($ch, CURLOPT_UPLOAD, 1); + curl_setopt($ch, CURLOPT_INFILE, $fp); + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); + curl_exec ($ch); + $error_no = curl_errno($ch); + curl_close ($ch); + if ($error_no == 0) { + $error = 'File uploaded succesfully.'; + } else { + $error = 'File upload error.'; + } + return error_no; + } + + function buildBackup($useExtendedFilename, $backupPath) { + // if parameter extendedFilename is passed with value 1 the filename changes + // from backup.tar.gz to openWB_backup_YYYY-MM-DD_HH-MM-SS.tar.gz + + echo ""; + $timestamp = date("Y-m-d") . "_" . date("H-i-s"); + if ( $useExtendedFilename ) { + $filename = "openWB_backup_" . $timestamp . ".tar.gz" ; + } else { + $filename = "backup.tar.gz" ; + } + + // first empty backup-directory + echo ""; + array_map( "unlink", array_filter((array) glob($backupPath . "*") ) ); + // then create new backup-file + exec("tar --exclude='/var/www/html/openWB/web/backup' --exclude='/var/www/html/openWB/.git' -czf ". $backupPath . $filename . " /var/www/html/"); + + return $filename; + } + +?> + + + + + + + + + + Backup erstellen + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

Backup erstellen

+
+ Backup-Datei erfolgreich + + auf + erstellt. +
+ +
+ "; + echo $globalErrorMessage."
"; + ?> + +
+ +
+ +
+
+ Sie befinden sich hier: System/Backup erstellen +
+
+ + + + + From 4762029c95a1a00aeef6bf1a76c559ea8a645612 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Lendholt Date: Fri, 1 Dec 2023 11:56:35 +0100 Subject: [PATCH 3/7] changed bevaviour and labeling of the navbar --- web/settings/navbar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/settings/navbar.html b/web/settings/navbar.html index e9c6b4279..d47da29a2 100644 --- a/web/settings/navbar.html +++ b/web/settings/navbar.html @@ -64,7 +64,7 @@ System