public function current() { $count = Host::where("id", "!=", 0)->get()->count(); $backups = Backup::where(DB::raw('YEAR(created_at)'), '=', "2013")->where(DB::raw('MONTH(created_at)'), '=', "01")->where(DB::raw('DAY(created_at)'), '=', "21")->where('type', '=', 'cron')->get(array('id', 'host_id', 'hostname', 'status', 'files_original_size', 'db_original_size', 'total_size')); $report = ""; foreach ($backups as $backup) { $backup["files_original_size"] = $this->ghs($backup["files_original_size"]); $backup["db_original_size"] = $this->ghs($backup["db_original_size"]); $backup["total_size"] = $this->ghs($backup["total_size"]); if ($backup["status"] == "ok") { $row = '<tr class="success">'; } if ($backup["status"] == "broken") { $row = '<tr class="danger">'; } if ($backup["status"] == "removed") { $row = '<tr class="warning">'; } $row .= "<td>" . $backup["id"] . "</td>"; $row .= "<td>" . $backup["host_id"] . "</td>"; $row .= "<td>" . $backup["hostname"] . "</td>"; $row .= "<td>" . $backup["files_original_size"] . "</td>"; $row .= "<td>" . $backup["db_original_size"] . "</td>"; $row .= "<td>" . $backup["total_size"] . "</td>"; $row .= "</tr>"; $report .= $row; } return View::make('reports.daily')->with('report', $report)->with('hosts_count', $count)->with('email', Auth::user()->email); }
public function fire() { $hosts = Host::where('state', '!=', 'disabled')->where('cron', '=', 'yes')->get(array('id')); foreach ($hosts as $host) { Queue::push('BackupController@dailyBackup', array('id' => $host->id)); } }
public function getViewDate($id, $year, $month) { // if ((Session::token() != Input::get('_token')) && !(Request::ajax())) // { // App::abort(401, 'You are not authorized or using wrong request type or csrf token not provided.'); // } $count = Host::where("id", "!=", 0)->get()->count(); //ignoring service host $backups = Backup::select('id', 'created_at', 'status', 'file', 'username', 'total_size', 'type')->where('host_id', '=', $id)->where(DB::raw('YEAR(created_at)'), '=', $year)->where(DB::raw('MONTH(created_at)'), '=', $month)->orderBy('created_at', 'desc')->get(); return View::make('backups.show')->with('backups', $backups)->with('backups', $backups)->with('hosts_count', $count)->with('email', Auth::user()->email); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show() { if (Session::token() != Input::get('_token') || !Request::ajax()) { App::abort(401, 'You are not authorized or using wrong request type or csrf token not provided.'); } $req = Input::get('request'); $hosts = Host::where('host', 'LIKE', '%' . $req . '%')->where('id', '!=', 0)->get(array('id', 'host', 'name', 'state', 'parent', 'type')); if ($req == "") { $hosts = Host::where('id', '!=', 0)->get(array('id', 'host', 'name', 'state', 'parent', 'type')); } return View::make('hosts/search')->withHosts($hosts); }
static function getOuHosts($ouid, $getIdArray = false) { $hosts = array(); $ids = array(); foreach (Host::where('ou_id', $ouid)->find_many() as $host) { $hosts[] = $host->hostname; $ids[] = $host->id; } if ($getIdArray) { return $ids; } return implode(' ', $hosts); }
public function cron_backup($host, $user, $entry, $backup) { $hosts = Host::where('id', '!=', 0)->get(array('id', 'host', 'name', 'state', 'parent', 'type')); return View::make('hosts/index')->withHosts($hosts); }
Route::get('/', array('as' => 'home', function () { if (!Auth::guest()) { return Redirect::route('hosts.index'); } return View::make('login', array('authUrl' => Auth::getAuthUrl())); })); //login route Route::get('/login', array('before' => 'google-finish-authentication', 'uses' => 'UsersController@login', 'as' => 'login')); // Host route group Route::group(array('before' => 'authent'), function () { Route::get('/dashboard', array('as' => 'dashboard', function () { return Redirect::route('hosts.index'); })); // backups route Route::resource('hosts', 'HostController'); //Route::controller('host', 'BackupController'); Route::get('host/{id}', 'BackupController@getView'); Route::get('report', 'ReportController@current'); Route::get('host/{id}/{year}/{month}', 'BackupController@getViewDate'); Route::get('/logout', function () { Auth::logout(); return Redirect::to('/'); }); //Route::get('/migration', array('uses' => 'MigrationsController@show', 'as' => 'migration')); //topmenu event to display hosts count and userdata View::composer(array('dashboard', 'hosts/*', 'backups/*', 'report'), function ($view) { $count = Host::where("id", "!=", 0)->get()->count(); //ignoring service host $view->with('hosts_count', $count)->with('email', Auth::user()->email); }); });
public function dailyBackup($job, $data) { if ($job->attempts() > 3) { $job->delete(); } //################################### select each backup $hosts = Host::where('id', '=', $data["id"])->where('state', '!=', 'disabled')->where('cron', '=', 'yes')->get(array('id', 'parent', 'name', 'host', 'type', 'ssh_login', 'ssh_pwd', 'storage', 'source', 'db_name', 'db_user', 'db_pwd')); foreach ($hosts as $host) { $backup = new Backup(); $backup->host_id = $host["id"]; $backup->hostname = $host["host"]; $backup->type = "cron"; //################################### folders check $dir = $host["storage"] . "/auto/"; if (!is_dir($dir)) { // creating if not exists and setting owner $cmd = "mkdir -p " . $dir . " && chown -R ftpuser:ftpgroup /backups/web " . $dir; exec($cmd); } //##################################### -- //##################################### generating ssh configuration Config::set('remote.connections.runtime.host', $host->host); Config::set('remote.connections.runtime.port', '22'); Config::set('remote.connections.runtime.username', $host->ssh_login); if (!$host->ssh_pwd) { Config::set('remote.connections.runtime.password', ''); Config::set('remote.connections.runtime.key', '/root/.ssh/id_rsa'); } else { Config::set('remote.connections.runtime.password', $host->ssh_pwd); Config::set('remote.connections.runtime.key', ''); } Config::set('remote.connections.runtime.keyphrase', ''); Config::set('remote.connections.runtime.root', '~/'); $dtime = date('d.m.y_H.i'); $FileName = $host->host . "_" . $dtime; $path = $dir . $host->host . "_" . $dtime . ".tar"; $dbpath = $dir . $host->host . "_" . $dtime . ".sql"; //##################################### -- //##################################### backup type: ssh-all if ($host->type == "ssh-all") { SSH::into('runtime')->run(array("tar -cf ~/" . $FileName . ".tar " . $host->source, "mysqldump -u" . $host->db_user . " -p" . $host->db_pwd . " --lock-tables --databases " . $host->db_name . "> ~/" . $FileName . ".sql")); // downloading files SSH::into('runtime')->get($FileName . ".tar", $path); SSH::into('runtime')->get($FileName . ".sql", $dbpath); // continue to local actions if success if (file_exists($dbpath) && file_exists($path)) { // adding sql file to archive exec("tar -rf " . $path . " " . $dbpath); // compressing exec("bzip2 -zfkv9 " . $path); $backup->file = $path . ".bz2"; $backup->total_size = filesize($path . ".bz2"); // cleanup local and remote files SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar", "rm ~/" . $FileName . ".sql")); $backup->status = "ok"; exec("rm " . $path); exec("rm " . $dbpath); } else { $backup->status = "broken"; } $backup->save(); //##################################### permissions $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir; exec($set_perm); } //##################################### -- //##################################### backup type: ssh-files if ($host->type == "ssh-files") { SSH::into('runtime')->run(array("tar -cf ~/" . $FileName . ".tar " . $host->source)); // downloading files SSH::into('runtime')->get($FileName . ".tar", $path); // continue to local actions if success if (file_exists($path)) { // compressing exec("bzip2 -zfkv9 " . $path); $backup->file = $path . ".bz2"; $backup->total_size = filesize($path . ".bz2"); // cleanup local and remote files SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar")); $backup->status = "ok"; exec("rm " . $path); } else { $backup->status = "broken"; } //##################################### permissions $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir; exec($set_perm); $backup->save(); } //##################################### -- //##################################### backup type: ssh-db if ($host->type == "ssh-db") { SSH::into('runtime')->run(array("mysqldump -u" . $host->db_user . " -p" . $host->db_pwd . " --lock-tables --databases " . $host->db_name . "> ~/" . $FileName . ".sql", "tar -cf ~/" . $FileName . ".tar " . "~/" . $FileName . ".sql")); // downloading files SSH::into('runtime')->get($FileName . ".tar", $path); // continue to local actions if success if (file_exists($path)) { // compressing exec("bzip2 -zfkv9 " . $path); $backup->file = $path . ".bz2"; $backup->total_size = filesize($path . ".bz2"); // cleanup local and remote files SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar", "rm ~/" . $FileName . ".sql")); $backup->status = "ok"; exec("rm " . $path); } else { $backup->status = "broken"; } //##################################### permissions $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir; exec($set_perm); $backup->save(); } //##################################### -- } $job->delete(); }