Пример #1
0
<?php

include "settings.php";
include "databaseConnect.php";
function dumpDB()
{
    $link = Connect();
    $query = $link->prepare("SELECT word,answer  FROM ia_dictionary");
    // change to match your db
    $query->execute();
    $res = $query->fetchall(PDO::FETCH_ASSOC);
    return $res;
}
echo json_encode(dumpDB());
Пример #2
0
    {
        setStatusBackup('Error: Failed to open zip file.', 0);
        die('Failed to open zip file.');
    }

    /* Backup the database if we're not in attachments-only mode. */
    if (!$attachmentsOnly)
    {
        include_once('modules/install/backupDB.php');
        
        $SQLDumpPath = $directory . 'catsbackup.sql';
    
        /* Dump SQL tables to the filesystem. This will dump both a complete
         * schema and special CATS restore files split into ~1MB chunks.
         */
        $totalFiles = dumpDB($db, $SQLDumpPath, true);
        markCompleted('Dumping tables...');

        /* Add the complete database dump to the zip file. */
        setStatusBackup('Compressing database...', 0);
        $status = $zipFileCreator->addFileFromDisk(
            'database',
            $SQLDumpPath
        );
        @unlink($SQLDumpPath);

        /* Fail out if we were't successful writing the file to the zip. */
        if (!$status)
        {
            setStatusBackup('Error: Failed to add database to zip file.', 0);
            $zipFileCreator->abort();
Пример #3
0
function makeBackup($siteID, $backupType = BACKUP_TAR, $logFile = null)
{
    global $stderr;
    global $stdout;
    if ($logFile !== null) {
        $stdout = $logFile;
        $stderr = $logFile;
    }
    $db = DatabaseConnection::getInstance();
    $random = rand();
    $i = 0;
    while (file_exists('scripts/backup/' . $random) && $i++ < 30000) {
        $random = rand();
    }
    if (file_exists('scripts/backup/' . $random)) {
        fwrite($stderr, "Unable to create temporary directory.\n");
        die;
    }
    if (!file_exists('scripts/backup')) {
        mkdir('scripts/backup');
    }
    if (!file_exists('scripts/backup/' . $random)) {
        mkdir('scripts/backup/' . $random);
    }
    exec('touch scripts/backup/index.php');
    exec('echo deny from all > scripts/backup/.htaccess');
    fwrite($stdout, "Temporary directory is backup/" . $random . ". \n\n");
    $primarySiteID = $siteID;
    $siteIDStack = array($siteID);
    while ($siteID = array_pop($siteIDStack)) {
        $rsSite = $db->getAssoc('SELECT * FROM site WHERE site_id = ' . $siteID);
        fwrite($stdout, "Backing up '" . $rsSite['name'] . "' (database)... ");
        @mkdir('scripts/backup/' . $random . '/' . $siteID);
        @mkdir('scripts/backup/' . $random . '/' . $siteID . '/db');
        dumpDB($db, 'scripts/backup/' . $random . '/' . $siteID . '/db/catsbackup.sql', false, true, $siteID);
        fwrite($stdout, "(attachments)... ");
        dumpAttachments($db, 'scripts/backup/' . $random . '/' . $siteID . '/', $siteID);
        if ($backupType == BACKUP_TAR) {
            fwrite($stdout, "(tar.bz2)... ");
            exec('tar -cjf scripts/backup/' . $random . '/' . $siteID . '.tar.bz2 scripts/backup/' . $random . '/' . $siteID . '/*');
            exec('rm -rf scripts/backup/' . $random . '/' . $siteID . '/');
            $rsSites = $db->getAllAssoc('SELECT * FROM site WHERE parent_site_id = ' . $siteID);
            foreach ($rsSites as $index => $data) {
                array_push($siteIDStack, $data['site_id']);
            }
        } else {
            if ($backupType == BACKUP_ZIP) {
                //ZIP backup
                fwrite($stdout, "(zip)... ");
                if (is_executable('/usr/local/bin/zip')) {
                    exec('/usr/local/bin/zip -r scripts/backup/' . $random . '/' . $siteID . '.zip scripts/backup/' . $random . '/' . $siteID . '/*');
                } else {
                    exec('zip -r scripts/backup/' . $random . '/' . $siteID . '.zip scripts/backup/' . $random . '/' . $siteID . '/*');
                }
                exec('rm -rf scripts/backup/' . $random . '/' . $siteID . '/');
                $rsSites = $db->getAllAssoc('SELECT * FROM site WHERE parent_site_id = ' . $siteID);
                foreach ($rsSites as $index => $data) {
                    array_push($siteIDStack, $data['site_id']);
                }
            } else {
                //CATS Format backup
                fwrite($stdout, "(bak)... ");
                chdir('scripts/backup/' . $random . '/' . $siteID . '');
                if (is_executable('/usr/local/bin/zip')) {
                    exec('/usr/local/bin/zip -r ../' . $siteID . '.zip *');
                } else {
                    exec('zip -r ../' . $siteID . '.zip *');
                }
                exec('rm -rf *');
                chdir('../../../..');
            }
        }
        fwrite($stdout, ".\n\n");
    }
    if ($backupType == BACKUP_TAR) {
        fwrite($stdout, "Archiving master tar file... \n\n");
        exec('tar -cf scripts/backup/' . $primarySiteID . '_full.tar scripts/backup/' . $random . '/');
        exec('rm -rf scripts/backup/' . $random);
    } else {
        if ($backupType == BACKUP_ZIP) {
            fwrite($stdout, "Archiving master zip file... \n\n");
            if (file_exists('scripts/backup/' . $primarySiteID . '_full.zip')) {
                @unlink('scripts/backup/' . $primarySiteID . '_full.zip');
            }
            if (is_executable('/usr/local/bin/zip')) {
                exec('/usr/local/bin/zip scripts/backup/' . $primarySiteID . '_full.zip scripts/backup/' . $random . '/*');
            } else {
                exec('zip scripts/backup/' . $primarySiteID . '_full.zip scripts/backup/' . $random . '/*');
            }
            //exec('rm -rf scripts/backup/'.$random);
        } else {
            fwrite($stdout, "Moving file to scripts\\backup...  \n\n");
            //CATS Backup
            exec('mv scripts/backup/' . $random . '/' . $primarySiteID . '.zip scripts/backup/catsbackup.bak');
            exec('rm -rf scripts/backup/' . $random);
        }
    }
    if (php_sapi_name() == 'cli') {
        fwrite($stdout, "Archive complete!  \n\n");
    }
}