Skip to content

A live bird collage card for your Home Assistant dashboard.

add downloadable backup

frederikcb8abd4f22cc
diff --git a/scripts/backup.php b/scripts/backup.php
new file mode 100644
index 00000000..8da51233
--- /dev/null
+++ b/scripts/backup.php
@@ -0,0 +1,22 @@
+<?php
+
+define('__ROOT__', dirname(dirname(__FILE__)));
+require_once(__ROOT__.'/scripts/common.php');
+
+$user = get_user();
+$home = get_home();
+ensure_authenticated('You must be authenticated to download backup files.');
+
+set_timezone();
+$date = new DateTime();
+$date_str = $date->format("Ymd\\THis");
+
+header("Content-Description: File Transfer");
+header("Content-Type: application/octet-stream");
+header("Content-Disposition: attachment; filename=\"backup-$date_str.tar\"");
+
+$err=null;
+set_time_limit(0);
+passthru("sudo -u $user $home/BirdNET-Pi/scripts/backup_data.sh -a backup -f -", $err);
+debug_log(strval($err));
+exit();
diff --git a/scripts/system_controls.php b/scripts/system_controls.php
index f3aaca0d..80d7b775 100644
--- a/scripts/system_controls.php
+++ b/scripts/system_controls.php
@@ -49,7 +49,7 @@ function update() {
<button type="submit" name="submit" value="sudo clear_all_data.sh" onclick="return confirm('Clear ALL Data? Note that this cannot be undone and will take up to 90 seconds.')">Clear ALL data</button>
</div>
</form>
-</div>
+<div><a href="scripts/backup.php" download ><button onclick="return confirm('Download backup? Note that this could take a long time.')">Download backup</button></a></div>
<?php
$cmd="cd ".$home."/BirdNET-Pi && sudo -u ".$user." git rev-list --max-count=1 HEAD";
$curr_hash = shell_exec($cmd);