mirror of
https://github.com/unraid/webgui.git
synced 2026-04-28 05:49:35 -05:00
Added "USB backup" function
This commit is contained in:
@@ -13,6 +13,34 @@ Title="Flash Device Settings"
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<style>ul,li{margin:0;padding-top:0;padding-bottom:0;}</style>
|
||||
|
||||
<script>
|
||||
function cleanUp(zip) {
|
||||
if (document.hasFocus()) {
|
||||
$('input[value="Creating USB backup..."]').val('USB backup').prop('disabled',false);
|
||||
$('#pleaseWait').hide('slow');
|
||||
$.post('/webGui/include/Download.php',{cmd:'unlink',file:zip});
|
||||
} else {
|
||||
setTimeout(function(){cleanUp(zip);},2000);
|
||||
}
|
||||
}
|
||||
function backup() {
|
||||
$('input[value="USB backup"]').val('Creating USB backup...').prop('disabled',true);
|
||||
$('#pleaseWait').show('slow');
|
||||
$.post('/webGui/include/Download.php',{cmd:'backup'},function(zip) {
|
||||
if (zip) {
|
||||
location = '/'+zip;
|
||||
setTimeout(function(){cleanUp(zip);},4000);
|
||||
} else {
|
||||
$('input[value="Creating USB backup..."]').val('USB backup');
|
||||
$('#pleaseWait').hide('slow');
|
||||
swal('Creation error','Insufficient free disk space available','error');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
Flash Vendor:
|
||||
: <?=$var['flashVendor'];?>
|
||||
|
||||
@@ -35,4 +63,6 @@ Flash GUID:
|
||||
<?endif;?>
|
||||
|
||||
|
||||
: <input type="button" value="Done" onclick="done()">
|
||||
: <input type="button" value="USB backup" onclick="backup()"><input type="button" value="Done" onclick="done()">
|
||||
|
||||
<br><div id="pleaseWait" style="display:none;font-weight:bold;color:red;text-align:center">Please wait... creating USB backup zip file (this may take several minutes)</div>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
$file = $_POST['file'];
|
||||
switch ($_POST['cmd']) {
|
||||
case 'save':
|
||||
@@ -36,5 +36,13 @@ case 'diag':
|
||||
exec("$docroot/webGui/scripts/diagnostics $anon ".escapeshellarg("$docroot/$file"));
|
||||
echo "/$file";
|
||||
break;
|
||||
}
|
||||
case 'unlink':
|
||||
$disk = exec("ls -l '$docroot/$file'");
|
||||
$disk = substr($disk,strpos($disk,'>')+2);
|
||||
exec("rm -f '$docroot/$file' '$disk'");
|
||||
break;
|
||||
case 'backup':
|
||||
echo exec("$docroot/webGui/scripts/usb_backup");
|
||||
break;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/php -q
|
||||
<?PHP
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
$var = file_exists('/var/local/emhttp/var.ini') ? parse_ini_file('/var/local/emhttp/var.ini') : [];
|
||||
$out = ['previous','syslinux'];
|
||||
|
||||
$server = isset($var['NAME']) ? str_replace(' ','_',strtolower($var['NAME'])) : 'tower';
|
||||
$mydate = date('Ymd-Hi');
|
||||
$backup = "$server-usb-backup-$mydate.zip";
|
||||
|
||||
list($used,$free) = explode(',',exec("df /boot|awk 'END{print $3,$4}'"));
|
||||
$usb = $free > $used;
|
||||
foreach (glob('/mnt/user/*',GLOB_ONLYDIR) as $share) {
|
||||
$free = exec("df $share|awk 'END{print $4}'");
|
||||
if ($free > $used) {$zip = $share; break;}
|
||||
}
|
||||
$zip = $zip ? "$zip/$backup" : ($usb ? "/boot/$backup" : "");
|
||||
if ($zip) {
|
||||
chdir("/boot");
|
||||
foreach (glob("*",GLOB_NOSORT+GLOB_ONLYDIR) as $folder) {
|
||||
if (in_array($folder,$out)) continue;
|
||||
exec("zip -qr ".escapeshellarg($zip)." ".escapeshellarg($folder));
|
||||
}
|
||||
foreach (glob("*",GLOB_NOSORT) as $file) {
|
||||
if (is_dir($file)) continue;
|
||||
exec("zip -q ".escapeshellarg($zip)." ".escapeshellarg($file));
|
||||
}
|
||||
symlink($zip,"$docroot/$backup");
|
||||
echo $backup;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user