示例#1
0
 static function sharedInstance()
 {
     if (is_null(self::$sharedInstance)) {
         self::$sharedInstance = new self();
     }
     return self::$sharedInstance;
 }
示例#2
0
function index()
{
    $res = ModelJob::sharedInstance()->findAll();
    if (is_array($res)) {
        echo '<table>';
        echo '<tr>';
        echo '<td style="width: 30px;">ID</td>';
        echo '<td style="width: 150px;">Name</td>';
        echo '<td style="width: 50px;">Status</td>';
        echo '</tr>';
        foreach ($res as $job) {
            echo '<tr>';
            echo '<td>' . $job->id . '</td>';
            echo '<td>' . $job->jobConfName . '</td>';
            echo '<td>' . $job->status . '</td>';
            echo '</tr>';
        }
        echo '</table>';
        //Make files downloadable
        $hasBackup = false;
        $backupdir = './ky_backups/';
        $files = glob($backupdir . '*.*');
        $exclude_files = array('.', '..');
        if (!in_array($files, $exclude_files)) {
            // Sort files by modified time, latest to earliest
            // Use SORT_ASC in place of SORT_DESC for earliest to latest
            if (count($files) > 1) {
                array_multisort(array_map('filemtime', $files), SORT_NUMERIC, SORT_DESC, $files);
                $hasBackup = true;
            }
        }
        if (!empty($files)) {
            $partsDb = pathinfo($files[0]);
            $basenameDb = $partsDb['basename'];
            $dbSize = filesize($files[0]);
            $dbSize = $dbSize / pow(1024, 2);
            $dbSize = str_replace(".", ",", strval(round($dbSize, 2))) . " MB";
            $partsF = pathinfo($files[1]);
            $basenameF = $partsF['basename'];
            $fileSize = filesize($files[1]);
            $fileSize = $fileSize / pow(1024, 2);
            $fileSize = str_replace(".", ",", strval(round($fileSize, 2))) . " MB";
            echo '<div class="border-top"> Last backup on: ' . date("F d Y H:i:s.", filemtime($files[0])) . '<br/>';
            echo '<a href="./ky_backups/' . $basenameDb . '">Download Database (' . $dbSize . ')</a><br/>';
            echo '<a href="./ky_backups/' . $basenameF . '">Download Files (' . $fileSize . ').</a><br/></div>';
        }
    }
}
示例#3
0
文件: job.php 项目: Kalianey/kybackup
function curlBackup($params)
{
    $id = (int) $params['id'];
    $backup = Backup::sharedInstance();
    $modelJob = ModelJob::sharedInstance();
    ini_set("max_execution_time", 0);
    $jobConf = ModelJobConf::sharedInstance()->findById($id)[0];
    $db = ModelDb::sharedInstance()->findById((int) $jobConf->dbId)[0];
    $path = ModelPath::sharedInstance()->findById((int) $jobConf->pathId)[0];
    if (!is_null($jobConf)) {
        $job = new EntityJob();
        $job->jobConfId = $jobConf->id;
        $job->jobConfName = $jobConf->name;
        $job->starttime = time();
        $job->status = "file";
        $job->uploaded = 0;
        $job->deleted = 0;
        $modelJob->save($job);
        // update job status to "file" and save()
        $filename = $backup->backupFiles($path->path, $path->ignored);
        $job->filename = $filename;
        // update job status to "db" and save()
        $job->status = "db";
        $modelJob->save($job);
        $dbfilename = $backup->backupDatabase($db->host, $db->username, $db->pass, $db->dbname);
        $job->dbfilename = $dbfilename;
        // update job status to "cleanup" and save()
        $job->status = "files";
        $modelJob->save($job);
        //$backup->deleteBackups(); //TODO: implement a counter int he config and delete old backups when necessary
        $job->status = "done";
        $job->endtime = time();
        $modelJob->save($job);
        echo "<br/>All done\n";
        //update job status to "complete" or "error" and save()
    }
    exit;
}
示例#4
0
 function _init()
 {
     // Define relationships
     self::$relationships = array('user' => ORM::has_many('\\Model\\Job\\User => \\Model\\User', array('select:id,name,username')));
     // Define fields definition
     self::$fields = array('id' => ORM::field('auto[3]'), 'name' => ORM::field('char[40]'), 'description' => ORM::field('string[100]'));
 }