Added "USB backup" function

This commit is contained in:
bergware
2017-07-14 01:51:39 +02:00
parent 6e82e2cc40
commit 8bcb70cffc
3 changed files with 84 additions and 3 deletions

View 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;
}
?>