Skip to content

Commit

Permalink
ncp-web: cache backup info
Browse files Browse the repository at this point in the history
Signed-off-by: nachoparker <[email protected]>
  • Loading branch information
nachoparker committed Apr 18, 2020
1 parent ff565d6 commit 1c45e0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

[v1.24.2](https://github.com/nextcloud/nextcloudpi/commit/1b9de02) (2020-04-06) build: small tweaks
[v1.24.3](https://github.com/nextcloud/nextcloudpi/commit/d6a8d3d) (2020-04-18) ncp-web: cache backup info

[v1.24.2 ](https://github.com/nextcloud/nextcloudpi/commit/ff565d6) (2020-04-06) build: small tweaks

[v1.24.1 ](https://github.com/nextcloud/nextcloudpi/commit/ae6c88f) (2020-04-06) nc-backup-auto: fix notify_admin

Expand Down
31 changes: 28 additions & 3 deletions ncp-web/backups.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@
<table class="dashtable backuptable">
<th>Date</th><th>Size</th><th>Compressed</th><th>Data</th><th></th>
HTML;
foreach ($bkps as $bkp)
{

$cache_file = '/var/www/ncp-web/backup-info-cache.cfg';
if (file_exists($cache_file)) {
$cache_str = file_get_contents($cache_file)
or exit("error opening ${cache_file}");

$cache = json_decode($cache_str, true) or [];
} else {
$cache = [];
}
foreach ($bkps as $bkp) {
$extension = pathinfo($bkp, PATHINFO_EXTENSION);
if ($extension === "tar" || $extension === "gz")
{
Expand All @@ -54,7 +63,18 @@
$size = round(filesize($bkp)/1024/1024) . " MiB";

$has_data = '';
exec("sudo /home/www/ncp-backup-launcher.sh bkp " . escapeshellarg($bkp) . " \"$compressed\"", $output, $ret);
$ret = null;

if (array_key_exists($bkp, $cache)) {
$ret = $cache[$bkp];
$cache_new[$bkp] = $ret;
}

if ($ret === null)
{
exec("sudo /home/www/ncp-backup-launcher.sh bkp " . escapeshellarg($bkp) . " \"$compressed\"", $output, $ret);
$cache_new[$bkp] = $ret;
}
if ($ret == 0)
$has_data = '';

Expand All @@ -74,6 +94,11 @@
echo '<input type="hidden" name="csrf-token" value="' . getCSRFToken() . '"/>';
}
}
$cache_str = json_encode($cache_new)
or exit('internal error');

file_put_contents($cache_file, $cache_str)
or exit("error writing ${cache_file}");
echo <<<HTML
</table>
</div>
Expand Down

0 comments on commit 1c45e0d

Please sign in to comment.