function mebackup_main() { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $cprogname = ucfirst($progname); initProgram('admin'); lxfile_mkdir("__path_program_home/selfbackup/self/__backup"); $backup = $login->getObject('general')->selfbackupparam_b; $dbf = $sgbl->__var_dbf; $pass = trim(lfile_get_contents("__path_program_root/etc/conf/{$progname}.pass")); $vd = createTempDir("/tmp", "mebackup"); $docf = "{$vd}/mebackup.dump"; // Issue #671 - Fixed backup-restore issue // exec("exec mysqldump --add-drop-table -u $progname -p$pass $dbf > $docf"); system("exec mysqldump --add-drop-table -u {$progname} -p{$pass} {$dbf} > {$docf}"); $string = @date('Y-M-d') . '-' . time(); $bfile = "{$sgbl->__path_program_home}/selfbackup/self/__backup/{$progname}-scheduled-masterselfbackup-{$string}.zip"; lxshell_zip($vd, $bfile, array("mebackup.dump")); lxfile_tmp_rm_rec($vd); if ($backup && $backup->isOn('selfbackupflag')) { try { lxbackup::upload_to_server($bfile, basename($bfile), $backup); } catch (Exception $e) { print "Sending warning to {$login->contactemail} ..\n"; lx_mail(null, $login->contactemail, "{$cprogname} Self Database Backup Upload Failed on " . date('Y-M-d') . " at " . date('H') . " Hours", "{$cprogname} Backup upload Failed due to {$e->getMessage()}\n"); } } $backup->rm_last_number = 20; $backup->nname = 'masterselfbackup'; lxbackup::clear_extra_backups('selfbackup', 'self', $backup); }
function lxshell_exists_in_zip($archive, $file) { $dir = createTempDir("/tmp", "testzip"); $ret = lxshell_unzip("__system__", $dir, $archive, array($file)); lxfile_tmp_rm_rec($dir); if (!$ret) { return true; } return false; }
public function do_restore($docd) { global $gbl, $sgbl, $login, $ghtml; $this->hardstop(); $this->createDisk(); $tmpbasedir = $this->main->__var_tmp_base_dir; if ($this->checkForSnapshot()) { lvm_remove($this->getSnapshotName()); if ($this->checkForSnapshot()) { throw new lxException("snapshot_for_this_exists_and_coudnt_remove"); } } if (!$this->main->isWindows()) { $mountpoint = $this->mount_this_guy(); lxshell_unzip_numeric_with_throw($mountpoint, $docd); //lxshell_return("tar", "-C", "$mountpoint/dev", "-xzf", "__path_program_root/file/vps-dev.tgz"); if ($this->main->__old_driver !== 'xen') { log_restore("Restoring {$this->main->nname} from a different driver {$this->main->__old_driver} to xen"); /* if (!lxfile_exists("__path_program_home/xen/template/{$this->main->ostemplate}.tar.gz")) { throw new lxException("migrating_from_{$this->main->__old_driver}_needs_osImage"); } */ //lxshell_return("tar", "-C", $mountpoint, "-xzf", "__path_program_home/xen/template/{$this->main->ostemplate}.tar.gz", "etc/rc.d", "sbin", "etc/hotplug.d", "etc/dev.d", "etc/udev", "lib", "usr", "bin", "etc/inittab", "etc/sysconfig"); //lxshell_return("tar", "-C", $mountpoint, "-xzf", "__path_program_home/xen/template/{$this->main->ostemplate}.tar.gz", "etc/rc.d", "sbin", "etc/hotplug.d", "etc/dev.d", "etc/udev", "lib", "usr", "bin", "etc/inittab"); lxfile_cp("../file/sysfile/xen/fstab", "{$mountpoint}/etc/fstab"); lxfile_cp("__path_program_root/file/sysfile/xen/inittab", "{$mountpoint}/etc/inittab"); lunlink("{$mountpoint}/etc/mtab"); lunlink("{$mountpoint}/etc/init.d/vzquota"); $this->copyKernelModules(); } lxfile_mkdir("{$mountpoint}/proc"); $this->createConfig(); $this->setMemoryUsage(); $this->setCpuUsage(); $this->setSwapUsage(); } else { $tmpdir = createTempDir($tmpbasedir, "lx_{$this->main->nname}_backup"); lxshell_unzip_with_throw($tmpdir, $docd); $partition = $this->getPartition(); lxshell_return("ntfsclone", "--restore-image", "--force", "-O", $partition, "{$tmpdir}/backup.img"); lxfile_tmp_rm_rec("{$tmpdir}"); $this->kpart_remove(); } $this->main->status = 'on'; try { $this->toggleStatus(); } catch (Exception $e) { } $this->start(); // Saving state doesn't seem to be an option. The thing is, it is the file system itself that's left in an inconsistent state, and there's little we can do about it. /* $statefile = "$mountpoint/__hypervm_xensavestate"; if (lxfile_exists($statefile)) { $tmp = lx_tmp_file("/tmp", "xen_ram"); lxfile_mv($statefile, $tmp); $this->umountThis(); $this->restoreXen($tmp); lunlink($tmp); } else { $this->start(); } */ }
function copy_script() { global $gbl, $sgbl, $login, $ghtml; if (!lxfile_exists("/script/")) { lxfile_tmp_rm_rec("/script"); lxfile_mkdir("/script"); lxfile_mkdir("/script/filter"); } lxfile_cp_content_file("htmllib/script/", "/script/"); lxfile_cp_content_file("../pscript", "/script/"); if (lxfile_exists("../pscript/vps/")) { if (lxfile_exists("/script/vps/")) { lxfile_mkdir("/script/vps"); } lxfile_cp_content_file("../pscript/vps/", "/script/vps/"); } lxfile_cp_content_file("../pscript/filter/", "/script/filter/"); lxfile_cp_content_file("htmllib/script/filter/", "/script/filter/"); lfile_put_contents("/script/programname", $sgbl->__var_program_name); lxfile_unix_chmod_rec("/script", "0755"); }
function top_level_simple_backup() { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; $dir = dirname($this->main->__var_bc_filename); $name = basename($this->main->__var_bc_filename); $firstname = strtil($name, "-"); lxfile_mkdir($dir); $list = lscandir_without_dot($dir); $bc = $this->do_backup(); $tmpdir = createTempDir("{$sgbl->__path_tmp}", "backupfile"); lfile_put_contents("{$tmpdir}/{$progname}.file", $this->main->__var_bc_metafile); lfile_put_contents("{$tmpdir}/{$progname}.metadata", $this->main->__var_bc_metadata); $newarray = lx_array_merge(array($bc[1], array("{$tmpdir}/{$progname}.file", "{$tmpdir}/{$progname}.metadata"))); if ($this->main->getZiptype() === 'zip') { lxshell_zip($bc[0], $this->main->__var_bc_filename, $newarray); } else { if ($this->main->getZiptype() === 'tar') { lxshell_tar($bc[0], $this->main->__var_bc_filename, $newarray); } else { lxshell_tgz($bc[0], $this->main->__var_bc_filename, $newarray); } } print_time("cpzip", "Copy and Zip"); lxfile_tmp_rm_rec("{$tmpdir}"); $this->do_backup_cleanup($bc); }
function do_restore($docd) { global $gbl, $sgbl, $login, $ghtml; $dbadmin = $this->main->__var_dbadmin; $dbpass = $this->main->__var_dbpassword; $vd = tempnam("/tmp", "mysqldump"); lunlink($vd); mkdir($vd); $docf = "{$vd}/mysql-{$this->main->dbname}.dump"; $ret = lxshell_unzip_with_throw($vd, $docd); if (!lxfile_exists($docf)) { throw new lxException('could_not_find_matching_dumpfile_for_db', '', ''); } $cont = lfile_get_contents($docf); if ($this->main->dbpassword) { $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, "-p{$this->main->dbpassword}", $this->main->dbname); } else { $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, $this->main->dbname); } if ($ret) { log_restore("Mysql restore failed.... Copying the mysqldump file {$docf} to {$sgbl->__path_kloxo_httpd_root}..."); lxfile_cp($docf, "__path_kloxo_httpd_root"); throw new lxException('mysql_error_could_not_restore_data', '', ''); } lunlink($docf); lxfile_tmp_rm_rec($vd); }
function do_restore($docd) { // Issue #671 - Fixed backup-restore issue global $gbl, $sgbl, $login, $ghtml; $dbadmin = $this->main->__var_dbadmin; $dbpass = $this->main->__var_dbpassword; $dbname = $this->main->dbname; $vd = tempnam("/tmp", "mysqldump"); lunlink($vd); mkdir($vd); // $docf = "$vd/mysql-{$this->main->dbname}.dump"; $docf = "{$vd}/mysql-{$dbname}.dump"; $ret = lxshell_unzip_with_throw($vd, $docd); if (!lxfile_exists($docf)) { throw new lxException('could_not_find_matching_dumpfile_for_db', '', ''); } /* // Issue #671 - how about for large data? $cont = lfile_get_contents($docf); if ($this->main->dbpassword) { $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, "-p{$this->main->dbpassword}", $this->main->dbname); } else { $ret = lxshell_input($cont, "__path_mysqlclient_path", "-u", $this->main->username, $this->main->dbname); } if ($ret) { log_restore("Mysql restore failed.... Copying the mysqldump file $docf to $sgbl->__path_kloxo_httpd_root..."); lxfile_cp($docf, "__path_kloxo_httpd_root"); throw new lxException('mysql_error_could_not_restore_data', '', ''); } lunlink($docf); lxfile_tmp_rm_rec($vd); */ $arg[0] = $sgbl->__path_mysqlclient_path; $arg[1] = "-u"; $arg[2] = $dbadmin; if ($dbpass) { $arg[3] = "-p'{$dbpass}'"; } else { $arg[3] = ""; } $arg[4] = $dbname; $cmd = implode(" ", $arg); $link = mysql_connect('localhost', $dbadmin, $dbpass); $result = mysql_query("CREATE DATABASE IF NOT EXISTS {$dbname}", $link); try { system("{$cmd} < {$docf}"); lunlink($docf); lxfile_tmp_rm_rec($vd); } catch (Exception $e) { throw new lxException('Error: ' . $e->getMessage(), $dbname); } }
function do_backup_cleanup($list) { lxfile_tmp_rm_rec($list[0]); }
static function getMetaData($file) { global $gbl, $sgbl, $login, $ghtml; $progname = $sgbl->__var_program_name; if (!lxfile_exists($file)) { throw new lxException('could_not_find_file', '', $file); } $tmpdir = lxbackup::createTmpDirIfitDoesntExist($file, false); print_time("create_tmp_dir", "Creating Tmp Directory"); $filename = recursively_get_file($tmpdir, "{$progname}.file"); // KLoxo has to recognize lxadmin's backup file. if (!$filename && $sgbl->isKloxoForRestore()) { $filename = recursively_get_file($tmpdir, "lxadmin.file"); } $rem = unserialize(file_get_contents($filename)); $bugfix = $tmpdir . $progname . ".file"; lxfile_rm($bugfix); $bugfix = $tmpdir . $progname . ".metadata"; lxfile_rm($bugfix); lxfile_tmp_rm_rec($tmpdir); lxfile_rm_rec($tmpdir); if (!$rem) { throw new lxException('backupfile_corrupted', ''); } return $rem; }