Exemplo n.º 1
0
     $requirements = getRequirements();
     $dirRights = getDirRights($paths);
     renderFile($viewFile, array('requirements' => $requirements, 'dirRights' => $dirRights, 'checkResult' => getCheckResult($requirements, $dirRights)));
     break;
 case BACKUP:
     $viewFile = $viewDir . 'upgrade.php';
     list($dbhost, $dbname, $port, $dbuser, $dbpwd, $dbprefix) = getDBConfig(CONFIG_FILE);
     list($result, $info, $target, $con) = getDBCon($dbhost, $port, $dbuser, $dbpwd);
     $version = getDBVersion($con, $dbname, $dbprefix);
     if ($_CFG['version'] == $_CFG['versionMap'][$version]) {
         @mysql_close($con);
         header('Location: index.php?action=upgraded');
     }
     if (isset($_GET['download'])) {
         if (!$result) {
             $dumpSql = backupDB($con, $dbname, $dbprefix);
             $compressSql = gzencode($dumpSql, 9);
             header('Content-type:application/text');
             header('Content-Disposition:attachment;filename=bugfree.sql.gz');
             echo $compressSql;
             break;
         }
     }
     renderFile($viewFile, array('version' => $version));
     @mysql_close($con);
     break;
 case UPGRADE:
     list($dbhost, $dbname, $port, $dbuser, $dbpwd, $dbprefix) = getDBConfig(CONFIG_FILE);
     list($result, $info, $target, $con) = getDBCon($dbhost, $port, $dbuser, $dbpwd);
     if (!$result) {
         $dbVersion = isset($_GET['dbversion']) ? $_GET['dbversion'] : null;
Exemplo n.º 2
0
$databases[] = 'zentao_04';
$databases[] = 'zentao_05';
$databases[] = 'zentao_06';
$databases[] = 'zentao_10';
$databases[] = 'zentao_101';
$databases[] = 'zentao_11';
$databases[] = 'zentao_12';
$databases[] = 'zentao_13';
$databases[] = 'zentao_14';
$databases[] = 'zentao_15';
if (!isset($argv[1])) {
    die(__FILE__ . ' restore' . "\n");
}
$cmd = $argv[1];
if ($cmd == 'backup') {
    backupDB();
}
if ($cmd == 'restore') {
    restore();
}
/* Backup new installed database. */
function backupDB()
{
    global $databases;
    foreach ($databases as $database) {
        $backupDatabase = "back_{$database}";
        mysql_query("DROP DATABASE {$backupDatabase}");
        mysql_query("CREATE DATABASE {$backupDatabase}");
        $cmd = "mysqldump -u root {$database} > {$database}.sql;\n";
        $cmd .= "mysql -uroot {$backupDatabase} < {$database}.sql;\n";
        $cmd .= "rm -fr {$database}.sql";
function backupDBs($hostname, $username, $password, $prefix, $post_backup_query = '')
{
    global $DATE, $s3, $mysql_backup_options;
    if (schedule == "hourly") {
        deleteHourlyBackups($prefix);
    }
    // Connecting, selecting database
    $link = mysql_connect($hostname, $username, $password) or die('Could not connect: ' . mysql_error());
    $query = 'SHOW DATABASES';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    $databases = array();
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        foreach ($row as $database) {
            $databases[] = $database;
        }
    }
    // Free resultset
    mysql_free_result($result);
    //Run backups on each DB found
    foreach ($databases as $database) {
        backupDB($hostname, $username, $password, $database, $prefix, $post_backup_query = '');
    }
    //Run post backup queries if needed
    if ($post_backup_query != '') {
        $result = mysql_query($post_backup_query) or die('Query failed: ' . mysql_error());
    }
    // Closing connection
    mysql_close($link);
}
Exemplo n.º 4
0
function run_workspace_backup($task, $args)
{
    throw new Exception("Gulliver backup is no longer supported, use processmaker command-line instead.");
    try {
        ini_set('display_errors', 'on');
        ini_set('error_reporting', E_ERROR);
        // the environment for poedit always is Development
        define('G_ENVIRONMENT', G_DEV_ENV);
        /* Look for -c and --compress in arguments */
        $compress = array_search('-c', $args);
        if ($compress === false) {
            $compress = array_search('--compress', $args);
        }
        if ($compress !== false) {
            unset($args[$compress]);
            /* We need to reorder the args if we removed the compress switch */
            $args = array_values($args);
            $compress = true;
        }
        /* Look for -c and --compress in arguments */
        $overwrite = array_search('-o', $args);
        if ($overwrite === false) {
            $overwrite = array_search('--overwrite', $args);
        }
        if ($overwrite !== false) {
            unset($args[$overwrite]);
            /* We need to reorder the args if we removed the compress switch */
            $args = array_values($args);
            $overwrite = true;
        }
        if (array_search('compress', $args)) {
            echo pakeColor::colorize("Compress is no longer an option, check if this is what you want\n", 'ERROR');
        }
        if (count($args) > 2 || count($args) == 0) {
            throw new Exception('wrong arguments specified');
        }
        $workspace = $args[0];
        /* Use system gzip if not in Windows */
        if ($compress && strtolower(reset(explode(' ', php_uname('s')))) != "windows") {
            /* Find the system gzip */
            exec("whereis -b gzip", $whereisGzip);
            $gzipPaths = explode(' ', $whereisGzip[0]);
            if (isset($gzipPaths[1])) {
                $gzipPath = $gzipPaths[1];
            }
            if (isset($gzipPath)) {
                echo "Using system gzip in {$gzipPath}\n";
            }
        }
        if (isset($args[1])) {
            $fileTar = $args[1];
            /* Check if the second argument is an absolute filename. If it is, use
             * it as the backup filename. Otherwise, use it as a filename relative
             * to the backups directory. This makes migration from previous versions
             * easier, which always expects a relative filename, while still accepting
             * absolute filenames.
             */
            if (dirname($fileTar) == '.') {
                printf("Using %s as root. Use an absolute filename to change it.\n", pakeColor::colorize(PATH_TRUNK . 'backups', 'INFO'));
                G::mk_dir(PATH_DATA . 'backups');
                $fileTar = PATH_DATA . 'backups' . PATH_SEP . $fileTar . '.tar';
                if ($compress) {
                    $fileTar .= '.gz';
                }
            }
            printf("Backing up workspace %s to %s\n", pakeColor::colorize($workspace, 'INFO'), pakeColor::colorize($fileTar, 'INFO'));
            if (!$overwrite && file_exists($fileTar)) {
                $overwrite = strtolower(prompt('Backup file already exists, do you want to overwrite? [Y/n]'));
                if (array_search(trim($overwrite), array("y", "")) === false) {
                    die;
                }
                $overwrite = true;
            }
        } else {
            G::mk_dir(PATH_DATA . 'backups');
            $fileBase = PATH_DATA . 'backups' . PATH_SEP . $workspace . '.tar';
            $fileTar = $fileBase;
            if ($compress) {
                $fileTar .= '.gz';
            }
            printf("Backing up workspace %s to %s\n", pakeColor::colorize($workspace, 'INFO'), pakeColor::colorize($fileTar, 'INFO'));
            /* To avoid confusion, we remove both .tar and .tar.gz */
            if (!$overwrite && (file_exists($fileBase) || file_exists($fileBase . '.gz'))) {
                $overwrite = strtolower(prompt('Backup file already exists, do you want to overwrite? [Y/n]'));
                if (array_search(trim($overwrite), array("y", "")) === false) {
                    die;
                }
                $overwrite = true;
            }
            if (file_exists($fileBase)) {
                unlink($fileBase);
            }
            if (file_exists($fileBase . ".gz")) {
                unlink($fileBase . '.gz');
            }
        }
        /* Remove the backup file before backing up. Previous versions didn't do
         * this, so backup files would increase indefinetely as new data was
         * appended to the tar file instead of replaced.
         */
        if (file_exists($fileTar)) {
            unlink($fileTar);
        }
        /* If using the system gzip, create the tar using a temporary filename */
        if (isset($gzipPath)) {
            $gzipFinal = $fileTar;
            $fileTar = tempnam(__FILE__, '');
        }
        $aSerializeData = get_infoOnPM($workspace);
        $dbFile = PATH_DB . $workspace . PATH_SEP . 'db.php';
        if (!file_exists($dbFile)) {
            throw new Exception("Invalid workspace, the db file does not exist, {$dbFile}");
        }
        $dbOpt = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
        G::LoadSystem('dbMaintenance');
        $oDbMaintainer = new DataBaseMaintenance($dbOpt[0], $dbOpt[1], $dbOpt[2]);
        try {
            $oDbMaintainer->connect("mysql");
        } catch (Exception $e) {
            echo "Problems contacting the database with the administrator user\n";
            echo "The response was: {$e->getMessage()}\n";
        }
        require_once $dbFile;
        require_once "propel/Propel.php";
        G::LoadSystem('templatePower');
        Propel::init(PATH_CORE . "config/databases.php");
        $configuration = Propel::getConfiguration();
        $connectionDSN = $configuration['datasources']['workflow']['connection'];
        printf("using DSN Connection %s \n", pakeColor::colorize($connectionDSN, 'INFO'));
        $con = Propel::getConnection('workflow');
        $sql = "show variables like 'datadir'";
        $stmt = $con->createStatement();
        $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
        $rs->next();
        $row = $rs->getRow();
        if (!is_array($row)) {
            throw new Exception("unable to execute query in database");
        }
        $dataDir = $row['Value'];
        if ($dataDir[count($dataDir) - 1] == '/') {
            $dataDir = substr($dataDir, count($dataDir) - 1);
        }
        printf("MySQL data dir %s \n", pakeColor::colorize($dataDir, 'INFO'));
        $sql = "SELECT VERSION();";
        $stmt = $con->createStatement();
        $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
        $rs->next();
        $row = $rs->getRow();
        $mysqlVersion = $row[0];
        $aSerializeData['DATABASE'] = $mysqlVersion;
        //new db restore rotines, by Erik <*****@*****.**> on May 17th, 2010
        //set the temporal directory for all tables into wf, rb, and rp databases
        $tmpDir = G::sys_get_temp_dir() . PATH_SEP . 'pmDbBackup' . PATH_SEP;
        //create the db maintenance temporal dir
        G::mk_dir($tmpDir);
        $fileMetadata = $tmpDir . 'metadata.txt';
        $sMetadata = file_put_contents($fileMetadata, serialize($aSerializeData));
        if ($sMetadata === false) {
            throw new Exception("Metadata file could not be written");
        }
        G::LoadThirdParty('pear/Archive', 'Tar');
        $tar = new Archive_Tar($fileTar);
        if (!isset($gzipPath)) {
            $tar->_compress = $compress;
        }
        /*** WORKFLOW DATABASE BACKUP ***/
        $dbSettings = getDataBaseConfiguration($configuration['datasources']['workflow']['connection']);
        backupDB($dbOpt[0], $dbOpt[1], $dbOpt[2], $dbSettings['dbname'], $tmpDir);
        printf("Copying folder: %s \n", pakeColor::colorize($tmpDir, 'INFO'));
        backupAddTarFolder($tar, $tmpDir . $dbSettings['dbname'] . PATH_SEP, $tmpDir);
        /*** RBAC DATABASE BACKUP ***/
        $dbSettings = getDataBaseConfiguration($configuration['datasources']['rbac']['connection']);
        backupDB($dbOpt[0], $dbOpt[1], $dbOpt[2], $dbSettings['dbname'], $tmpDir);
        printf("Copying folder: %s \n", pakeColor::colorize($tmpDir, 'INFO'));
        backupAddTarFolder($tar, $tmpDir . $dbSettings['dbname'] . PATH_SEP, $tmpDir);
        /*** RP DATABASE BACKUP ***/
        $dbSettings = getDataBaseConfiguration($configuration['datasources']['rp']['connection']);
        backupDB($dbOpt[0], $dbOpt[1], $dbOpt[2], $dbSettings['dbname'], $tmpDir);
        printf("Copying folder: %s \n", pakeColor::colorize($tmpDir, 'INFO'));
        backupAddTarFolder($tar, $tmpDir . $dbSettings['dbname'] . PATH_SEP, $tmpDir);
        $pathSharedBase = PATH_DATA . 'sites' . PATH_SEP . $workspace . PATH_SEP;
        printf("copying folder: %s \n", pakeColor::colorize($pathSharedBase, 'INFO'));
        backupAddTarFolder($tar, $pathSharedBase, PATH_DATA . 'sites');
        backupAddTarFolder($tar, $fileMetadata, dirname($fileMetadata));
        unlink($fileMetadata);
        $aFiles = $tar->listContent();
        $total = 0;
        foreach ($aFiles as $key => $val) {
            //    printf( " %6d %s \n", $val['size'], pakeColor::colorize( $val['filename'], 'INFO') );
            $total += $val['size'];
        }
        /* If using system gzip, compress the temporary tar to the original
         * filename.
         */
        if (isset($gzipPath)) {
            exec("gzip -c \"{$fileTar}\" > {$gzipFinal}", $output, $ret);
            if ($ret != 0) {
                /* The error message is in stderr, which should be displayed already */
                echo pakeColor::colorize("Error compressing backup", "ERROR") . "\n";
                die(1);
            }
            unlink($fileTar);
            $fileTar = $gzipFinal;
        }
        printMetadata($aSerializeData);
        printf("%20s %s \n", 'Backup File', pakeColor::colorize($fileTar, 'INFO'));
        printf("%20s %s \n", 'Files in Backup', pakeColor::colorize(count($aFiles), 'INFO'));
        printf("%20s %s \n", 'Total Filesize', pakeColor::colorize(sprintf("%5.2f MB", $total / 1024 / 1024), 'INFO'));
        printf("%20s %s \n", 'Backup Filesize', pakeColor::colorize(sprintf("%5.2f MB", filesize($fileTar) / 1024 / 1024), 'INFO'));
    } catch (Exception $e) {
        printf("Error: %s\n", pakeColor::colorize($e->getMessage(), 'ERROR'));
        exit(0);
    }
}
Exemplo n.º 5
0
    $timeLastBackup = date('Y-m-d H:i:s', strtotime(file_get_contents(HOME . "/../TEMP/LastBackup.txt")));
    if ($time_24h_ago >= strtotime($timeLastBackup)) {
        $timeToDoBackup = TRUE;
    } else {
        echo "No han pasado 24h desde el anterior Backup!<br/>";
    }
}
if ($timeToDoBackup || !$lastBackupLogExists) {
    $backupFilesName = "SharedSList_backup_files-" . date("Y.m.d") . '.zip';
    $backupsPath = HOME . "/../TEMP/backups/";
    $backupFiles = $backupsPath . $backupFilesName;
    $backupDBName = "SharedSList_backup_DB-" . date("Y.m.d") . '.sql';
    $backupDB = $backupsPath . $backupDBName;
    Zip(HOME, $backupFiles);
    // comprimimos la carpeta public_html
    backupDB($backupDB);
    // hacemos el backup de la BBDD
    Zip($backupDB, $backupDB . ".zip");
    // comprimimos el backup de la BBDD
    $dropbox = new DropboxClient(array('app_key' => DBOX_KEY, 'app_secret' => DBOX_SECRET, 'app_full_access' => false), 'en');
    // intentamos recuperar el token de acceso
    $access_token = load_token("access");
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($access_token);
    } elseif (!empty($_GET['auth_callback'])) {
        // cargamos el token recien creado
        $request_token = load_token($_GET['oauth_token']);
        if (empty($request_token)) {
            die('No se ha podido obtener el request token!');
        }
        // obtenemos y guardamos el token de acceso