Пример #1
0
function backup()
{
    build_progress_idb("{backup_database}", 20);
    $unix = new unix();
    $targetFilename = "/home/ArticaStatsBackup/backup.db";
    $su = $unix->find_program("su");
    @mkdir("/home/ArticaStatsBackup", 0777, true);
    @chmod("/home/ArticaStatsBackup", 0777);
    if (is_file($targetFilename)) {
        @unlink($targetFilename);
    }
    $InFluxBackupDatabaseDir = @file_get_contents("/etc/artica-postfix/settings/Daemons/InFluxBackupDatabaseDir");
    if ($InFluxBackupDatabaseDir == null) {
        $InFluxBackupDatabaseDir = "/home/artica/influx/backup";
    }
    $CompressFileName = "{$InFluxBackupDatabaseDir}/snapshot." . date("Y-m-d-H-i") . ".gz";
    @mkdir($InFluxBackupDatabaseDir, 0755, true);
    if (is_file($CompressFileName)) {
        build_progress_idb("{backup_database} already exists", 110);
    }
    $cmdline = "{$su} -c \"/usr/local/ArticaStats/bin/pg_dumpall -c --if-exists -S ArticaStats -f {$targetFilename} -h /var/run/ArticaStats\" ArticaStats";
    echo $cmdline . "\n";
    exec($cmdline, $results);
    build_progress_idb("{backup_database}", 30);
    if (!is_file($targetFilename)) {
        echo "{$targetFilename} No such file\n";
        while (list($num, $val) = each($results)) {
            echo "{$val}\n";
        }
        build_progress_idb("{backup_database} {failed}", 110);
        return;
    }
    build_progress_idb("{compressing}", 50);
    echo "Compress {$targetFilename}\n";
    echo "Destination {$CompressFileName}\n";
    if (!$unix->compress($targetFilename, $CompressFileName)) {
        build_progress_idb("{compressing} {failed}", 110);
        squid_admin_mysql(0, "Snaphost BigData database {failed} ( compress )", null, __FILE__, __LINE__);
        @unlink($targetFilename);
        @unlink($CompressFileName);
        return;
    }
    @unlink($targetFilename);
    $size = FormatBytes(@filesize($CompressFileName) / 1024);
    squid_admin_mysql(2, "Backup [" . basename($CompressFileName) . "] BigData database ({$size}) done", null, __FILE__, __LINE__);
    build_progress_idb("{scanning}", 80);
    ScanBackup();
    build_progress_idb("{backup_database} {success}", 100);
}
Пример #2
0
function install($filekey = 0, $OS)
{
    include_once dirname(__FILE__) . "/ressources/class.ccurl.inc";
    $unix = new unix();
    $filename = null;
    $MD5 = null;
    $DebianVersion = DebianVersion();
    if ($OS != $DebianVersion) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb Debian version incompatible!\n";
        }
        build_progress_idb("Incompatible system {$OS}<>{$DebianVersion}!", 110);
        die;
    }
    if ($filekey != 0) {
        $sock = new sockets();
        $ArticaTechNetHaProxyRepo = unserialize(base64_decode($sock->GET_INFO("ArticaTechNetHaProxyRepo")));
        $version = $ArticaTechNetHaProxyRepo[$filekey][$OS]["VERSION"];
        $filename = $ArticaTechNetHaProxyRepo[$filekey][$OS]["FILENAME"];
        $MD5 = $ArticaTechNetHaProxyRepo[$filekey][$OS]["MD5"];
        $URL = $ArticaTechNetHaProxyRepo[$filekey][$OS]["URL"];
    }
    $rmmod = $unix->find_program("rmmod");
    $depmod = $unix->find_program("depmod");
    $modprobe = $unix->find_program("modprobe");
    $ldconfig = $unix->find_program("ldconfig");
    echo "Downloading {$URL}\n";
    $curl = new ccurl($URL);
    $tmpdir = $unix->TEMP_DIR();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress_idb("{downloading}", 1);
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "download_progress";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Downloading {$filename}\n";
    }
    if (!$curl->GetFile("{$tmpdir}/{$filename}")) {
        build_progress_idb("{$curl->error}", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$curl->error}\n";
        }
        while (list($key, $value) = each($curl->errors)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$value}\n";
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, HaProxy unable to install....\n";
        }
        @unlink("{$tmpdir}/{$filename}");
        return;
    }
    if ($MD5 != null) {
        $DESTMD5 = md5_file("{$tmpdir}/{$filename}");
        if ($DESTMD5 != $MD5) {
            echo "{$DESTMD5}<>{$MD5}\n";
            @unlink("{$tmpdir}/{$filename}");
            build_progress_idb("{install_failed} {corrupted_package}", 110);
            return;
        }
    }
    build_progress_idb("{stopping_service}", 95);
    if (!is_file("/etc/init.d/haproxy")) {
        system("{$php} /usr/share/artica-postfix/exec.initslapd.php --haproxy");
    }
    system("/etc/init.d/firehol stop");
    system("/etc/init.d/haproxy stop");
    build_progress_idb("{extracting}", 96);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, extracting....\n";
    }
    $tar = $unix->find_program("tar");
    shell_exec("{$tar} xvf {$tmpdir}/{$filename} -C /");
    build_progress_idb("{installing} 1/1", 96);
    system("{$ldconfig}");
    if ($GLOBALS["PROGRESS"]) {
        build_progress_idb("{restarting_service}", 97);
        system("{$php} /usr/share/artica-postfix/exec.status.php --haproxy >/dev/null");
        system("/etc/init.d/artica-status restart --force");
        build_progress_idb("{restarting_service} 1/2", 98);
        system("/etc/init.d/haproxy restart");
        build_progress_idb("{restarting_service} 2/2", 98);
        system("/etc/init.d/firehol restart");
    }
    build_progress_idb("{refresh_status}", 98);
    build_progress_idb("{done}", 100);
}
Пример #3
0
function restore($targetFilename)
{
    build_progress_idb("{restore_database}", 20);
    $unix = new unix();
    if (is_file("/tmp/postgressql-restore.running")) {
        $pid = $unix->PIDOF("/usr/local/ArticaStats/bin/psql");
        if ($unix->process_exists($pid)) {
            $timepid = $unix->PROCCESS_TIME_MIN($pid);
            echo "Already running {$pid} since {$timepid}mn\n";
            return;
        }
        @unlink("/tmp/postgressql-restore.running");
    }
    if (is_file("/tmp/postgressql-restore.running")) {
        return;
    }
    if (!is_file($targetFilename)) {
        echo "targetFilename: {$targetFilename} no such file\n";
        build_progress_idb("{restore_database} {failed}", 110);
        return;
    }
    $basename = basename($targetFilename);
    if (!preg_match("#\\.gz\$#", $basename)) {
        echo "targetFilename: {$basename} do in gzip format\n";
        build_progress_idb("{restore_database} {failed}", 110);
        return;
    }
    $UnCompressFileName = $targetFilename . ".sql";
    $su = $unix->find_program("su");
    $gunzip = $unix->find_program("gunzip");
    build_progress_idb("{restore_database} {uncompress}", 50);
    if (!$unix->uncompress($targetFilename, $UnCompressFileName)) {
        echo "Unable to uncompress {$targetFilename}\n";
        build_progress_idb("{restore_database} {failed}", 110);
        return;
    }
    $psql = "/usr/local/ArticaStats/bin/psql -f {$UnCompressFileName}  -h /var/run/ArticaStats -U ArticaStats -w proxydb";
    $f[] = "#!/bin/sh";
    $f[] = ". /lib/init/vars.sh";
    $f[] = ". /lib/lsb/init-functions";
    $f[] = "LANG=en_US.UTF-8";
    $f[] = "HOME=/home/ArticaStats";
    $f[] = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games";
    $f[] = "rm /tmp/postgressql-restore.sh";
    $f[] = "if [ -f \"/tmp/postgressql-restore.running\" ]; then";
    $f[] = "exit";
    $f[] = "fi";
    $f[] = "touch /tmp/postgressql-restore.running\n";
    $cmdline = "{$psql}";
    $f[] = "{$cmdline}";
    $f[] = "echo \"OK FINISH\"";
    $f[] = "rm /tmp/postgressql-restore.running";
    $f[] = "touch /tmp/postgressql-restore.OK\n";
    if (is_file("/tmp/postgressql-restore.OK")) {
        @unlink("/tmp/postgressql-restore.OK");
    }
    @file_put_contents("/tmp/postgressql-restore.sh", @implode("\n", $f));
    @chmod("/tmp/postgressql-restore.sh", 0755);
    echo $cmdline;
    build_progress_idb("{restore_database} {run}", 50);
    $text = "{please_wait}";
    $i = 0;
    $prc = 60;
    while (true) {
        $i++;
        if (is_file("/tmp/postgressql-restore.OK")) {
            break;
        }
        build_progress_idb("{restore_database} {$text} ({$i})", $prc);
        sleep(3);
        if (is_file("/tmp/postgressql-restore.running")) {
            $pid = $unix->PIDOF("/usr/local/ArticaStats/bin/psql");
            $timepid = $unix->PROCCESS_TIME_MIN($pid);
            $size = $unix->DIRSIZE_BYTES_NOCACHE("/home/ArticaStatsDB");
            $array_load = sys_getloadavg();
            $internal_load = $array_load[0];
            $text = "{running} load:{$internal_load} {$pid} {since} {$timepid}mn " . FormatBytes($size / 1024);
            $prc = 70;
        }
    }
    build_progress_idb("{restore_database} {done}", 90);
    sleep(5);
    InfluxDbSize();
    build_progress_idb("{restore_database} {success}", 100);
}
Пример #4
0
function download_progress($download_size, $downloaded_size, $upload_size, $uploaded_size)
{
    if (!isset($GLOBALS["previousProgress"])) {
        $GLOBALS["previousProgress"] = 0;
    }
    if ($download_size == 0) {
        $progress = 0;
    } else {
        $progress = round($downloaded_size * 100 / $download_size);
    }
    if ($progress > $GLOBALS["previousProgress"]) {
        if ($progress < 95) {
            build_progress_idb("{downloading}", $progress);
        }
        $GLOBALS["previousProgress"] = $progress;
    }
}
Пример #5
0
function backup_database()
{
    $unix = new unix();
    $q = new mysql();
    $sock = new sockets();
    $InFluxBackupDatabaseDir = $sock->GET_INFO("InFluxBackupDatabaseDir");
    if ($InFluxBackupDatabaseDir == null) {
        $InFluxBackupDatabaseDir = "/home/artica/influx/backup";
    }
    $InFluxBackupDatabaseMaxContainers = intval("InFluxBackupDatabaseMaxContainers");
    if ($InFluxBackupDatabaseMaxContainers == 0) {
        $InFluxBackupDatabaseMaxContainers = 5;
    }
    $MaxContainers = 5;
    @mkdir($InFluxBackupDatabaseDir, 0755, true);
    $GetInfluxListenIP = GetInfluxListenIP();
    if ($GetInfluxListenIP == "0.0.0.0") {
        $GetInfluxListenIP = "127.0.0.1";
    }
    build_progress_idb("{backup} - {$GetInfluxListenIP}", 5);
    $tar = $unix->find_program("tar");
    @chdir("/home/artica/squid/InfluxDB");
    system("cd /home/artica/squid/InfluxDB");
    $time = time();
    $rm = $unix->find_program("rm");
    build_progress_idb("{backup}", 50);
    $cmd = "/opt/influxdb/influxd backup -host {$GetInfluxListenIP}:8089 {$InFluxBackupDatabaseDir}/snapshot.db";
    echo $cmd . "\n";
    system("{$cmd}");
    system("{$rm} -rf {$InFluxBackupDatabaseDir}/*.gz");
    $size = FormatBytes(@filesize("{$InFluxBackupDatabaseDir}/snapshot.db") / 1024);
    squid_admin_mysql(2, "Snaphost BigData database ({$size}) done", null, __FILE__, __LINE__);
    $size = $unix->DIRSIZE_BYTES_NOCACHE($InFluxBackupDatabaseDir);
    @file_put_contents("{$GLOBALS["BASEDIR"]}/influxdb_snapshotsize", $size);
    build_progress_idb("{done}", 100);
}