示例#1
0
 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();
     	}
     */
 }
示例#2
0
文件: weblib.php 项目: zseand/kloxo
 function do_restore($docd)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $name = $this->nname;
     $fullpath = "{$sgbl->__path_customer_root}/{$this->customer_name}/{$name}/";
     lxfile_mkdir($fullpath);
     lxshell_unzip_with_throw($fullpath, $docd);
 }
 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);
 }
示例#4
0
function getFromRemote($server, $filepass, $dt, $p)
{
    $bp = basename($p);
    if ($filepass['type'] === 'dir') {
        $tfile = lx_tmp_file("__path_tmp", "lx_{$bp}");
        getFromFileserv($server, $filepass, $tfile);
        lxfile_mkdir("{$dt}/{$bp}");
        lxshell_unzip_with_throw("{$dt}/{$bp}", $tfile);
        lunlink($tfile);
    } else {
        getFromFileserv($server, $filepass, "{$dt}/{$bp}");
    }
}
示例#5
0
 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_restore($docd)
 {
     $srv = new COM("SQLDMO.SQLServer");
     $srv->LoginSecure = true;
     try {
         $srv->Connect("localhost,1433");
     } catch (Exception $e) {
         throw new lxException('MsSql Connection is Failed', '', '');
     }
     $sBAKFilePath = "C:/SQL_Backup";
     if (!is_dir($sBAKFilePath)) {
         mkdir($sBAKFilePath, 0777);
     }
     $dir = "{$sBAKFilePath}/mssql";
     $mode = 0700;
     $sBAKFilePath = $dir . mt_rand(0, 9999999);
     mkdir($sBAKFilePath, $mode);
     $docf = "{$sBAKFilePath}/{$this->main->dbname}.bak";
     $ret = lxshell_unzip_with_throw($sBAKFilePath, $docd);
     if (!lxfile_exists($docf)) {
         throw new lxException('could_not_find_matching_dumpfile_for_db', '', '');
     }
     $bkp = new COM("SQLDMO.Restore");
     $dbname = $this->main->dbname;
     $bkp->Database = $dbname;
     $bkp->Files = $docf;
     $bkp->ReplaceDatabase = True;
     $bkp->SQLRestore($srv);
     print "\nRestored\n";
     $srv->DisConnect();
     lunlink($docf);
     lxfile_tmp_rm_rec($sBAKFilePath);
 }
示例#7
0
 function do_restore($docd)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $name = $this->main->getPathFromName('nname');
     $fullpath = "{$sgbl->__path_customer_root}/{$name}/";
     lxfile_mkdir($fullpath);
     lxshell_unzip_with_throw($fullpath, $docd);
     lxfile_generic_chown_rec($fullpath, "{$this->main->username}:{$this->main->username}");
     lxfile_generic_chown($fullpath, "{$this->main->username}:apache");
     lxfile_generic_chmod($fullpath, "0750");
 }
示例#8
0
 static function createTmpDirIfitDoesntExist($file, $real)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $progname = $sgbl->__var_program_name;
     $vd = tempnam("/tmp", "backup");
     if (!$vd) {
         throw new lxException('could_not_create_tmp_dir', '');
     }
     lunlink($vd);
     mkdir($vd);
     //
     // This is not a chmod inside the VM!
     // dont try to change it as restore will fail
     //
     lxfile_generic_chmod($vd, "0700");
     if ($real) {
         lxshell_unzip_with_throw($vd, $file);
     } else {
         if ($sgbl->isKloxoForRestore()) {
             try {
                 lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata"));
             } catch (Exception $e) {
                 lxshell_unzip_with_throw($vd, $file, array("*lxadmin.file", "*lxadmin.metadata"));
             }
         } else {
             lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata"));
         }
     }
     //
     // This is not a chmod inside the VM!
     // dont try to change it as restore will fail
     // Extra added by dterweij
     lxfile_generic_chmod($vd, "0700");
     return $vd;
 }
示例#9
0
 static function createTmpDirIfitDoesntExist($file, $real)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $progname = $sgbl->__var_program_name;
     $vd = tempnam("/tmp", "backup");
     if (!$vd) {
         throw new lxException('could_not_create_tmp_dir', '');
     }
     lunlink($vd);
     mkdir($vd);
     lxfile_generic_chmod($vd, "0700");
     if ($real) {
         lxshell_unzip_with_throw($vd, $file);
     } else {
         if ($sgbl->isKloxoForRestore()) {
             try {
                 lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata"));
             } catch (Exception $e) {
                 lxshell_unzip_with_throw($vd, $file, array("*lxadmin.file", "*lxadmin.metadata"));
             }
         } else {
             lxshell_unzip_with_throw($vd, $file, array("*{$progname}.file", "*{$progname}.metadata"));
         }
     }
     return $vd;
 }