mirror of
https://github.com/unraid/webgui.git
synced 2026-03-12 22:09:53 -05:00
Added "USB backup" function
This commit is contained in:
43
plugins/dynamix/scripts/usb_backup
Normal file
43
plugins/dynamix/scripts/usb_backup
Normal file
@@ -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