function InitializeStorage()
{
    if (USE_DEV_EMULATOR) {
        //Connect to the Storage Emulator
        $tableClient = new Microsoft_WindowsAzure_Storage_Table();
        $blobClient = new Microsoft_WindowsAzure_Storage_Blob();
        $queueClient = new Microsoft_WindowsAzure_Storage_Queue();
    } else {
        //Connect to Azure storage
        $tableClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_TABLES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY);
        $blobClient = new Microsoft_WindowsAzure_Storage_Blob(AZURE_BLOBS_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY);
        $queueClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_QUEUES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY);
    }
    //Create a table to store GuestBook Entries if it doesn't exist
    if (!$tableClient->tableExists(GB_TABLE_NAME)) {
        $result = $tableClient->createTable(GB_TABLE_NAME);
    }
    //Validate the blob container name
    if ($blobClient->isValidContainerName(GB_BLOB_CONTAINER)) {
        if (!$blobClient->containerExists(GB_BLOB_CONTAINER)) {
            //create it if it doesn't exist
            $result = $blobClient->createContainer(GB_BLOB_CONTAINER);
            //Make it public
            $blobClient->setContainerAcl(GB_BLOB_CONTAINER, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC);
            $blobClient->registerStreamWrapper();
        }
    }
    //Create a queue to send thumbnail jobs to a worker process if it doesn't exist
    $queue = $queueClient->createQueueIfNotExists(GB_QUEUE_NAME);
    return array($tableClient, $blobClient, $queueClient);
}
예제 #2
0
function dest_msazure()
{
    global $WORKING, $STATIC;
    $WORKING['STEPTODO'] = 2 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
    trigger_error(sprintf(__('%d. try sending backup to a Microsoft Azure (Blob)...', 'backwpup'), $WORKING['DEST_MSAZURE']['STEP_TRY']), E_USER_NOTICE);
    require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php';
    need_free_memory(4194304 * 1.5);
    try {
        $storageClient = new Microsoft_WindowsAzure_Storage_Blob($STATIC['JOB']['msazureHost'], $STATIC['JOB']['msazureAccName'], $STATIC['JOB']['msazureKey']);
        if (!$storageClient->containerExists($STATIC['JOB']['msazureContainer'])) {
            trigger_error(sprintf(__('Microsoft Azure container "%s" not exists!', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_ERROR);
            return;
        } else {
            trigger_error(sprintf(__('Connected to Microsoft Azure container "%s"', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_NOTICE);
        }
        trigger_error(__('Upload to MS Azure now started... ', 'backwpup'), E_USER_NOTICE);
        $result = $storageClient->putBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'], $STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
        if ($result->Name == $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']) {
            $WORKING['STEPTODO'] = 1 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
            trigger_error(sprintf(__('Backup transferred to %s', 'backwpup'), 'https://' . $STATIC['JOB']['msazureAccName'] . '.' . $STATIC['JOB']['msazureHost'] . '/' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']), E_USER_NOTICE);
            $STATIC['JOB']['lastbackupdownloadurl'] = $STATIC['WP']['ADMINURL'] . '?page=backwpupbackups&action=downloadmsazure&file=' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'] . '&jobid=' . $STATIC['JOB']['jobid'];
            $WORKING['STEPSDONE'][] = 'DEST_MSAZURE';
            //set done
        } else {
            trigger_error(__('Can not transfer backup to Microsoft Azure!', 'backwpup'), E_USER_ERROR);
        }
        if ($STATIC['JOB']['msazuremaxbackups'] > 0) {
            //Delete old backups
            $backupfilelist = array();
            $blobs = $storageClient->listBlobs($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir']);
            if (is_array($blobs)) {
                foreach ($blobs as $blob) {
                    $file = basename($blob->Name);
                    if ($STATIC['JOB']['fileprefix'] == substr($file, 0, strlen($STATIC['JOB']['fileprefix'])) and $STATIC['JOB']['fileformart'] == substr($file, -strlen($STATIC['JOB']['fileformart']))) {
                        $backupfilelist[] = $file;
                    }
                }
            }
            if (sizeof($backupfilelist) > 0) {
                rsort($backupfilelist);
                $numdeltefiles = 0;
                for ($i = $STATIC['JOB']['msazuremaxbackups']; $i < sizeof($backupfilelist); $i++) {
                    $storageClient->deleteBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $backupfilelist[$i]);
                    //delte files on Cloud
                    $numdeltefiles++;
                }
                if ($numdeltefiles > 0) {
                    trigger_error(sprintf(_n('One file deleted on Microsoft Azure container', '%d files deleted on Microsoft Azure container', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE);
                }
            }
        }
    } catch (Exception $e) {
        trigger_error(sprintf(__('Microsoft Azure API: %s', 'backwpup'), $e->getMessage()), E_USER_ERROR);
    }
    $WORKING['STEPDONE']++;
}
 /**
  * Check if a file can be created at a given storage path.
  * FS backends should check if the parent directory exists and the file is writable.
  * Backends using key/value stores should check if the container exists.
  *
  * @param $storagePath string
  * @return bool
  */
 public function isPathUsableInternal($storagePath)
 {
     list($c, $dir) = $this->resolveStoragePath($storagePath);
     if ($dir === null) {
         return false;
     }
     if (!$this->storageClient->containerExists($c)) {
         return false;
     }
     return true;
 }
예제 #4
0
 /**
  * Ensure storage has been initialized
  */
 protected function _ensureStorageInitialized()
 {
     if (!$this->_blobStorageClient->containerExists($this->_controlContainer)) {
         $this->_blobStorageClient->createContainer($this->_controlContainer);
     }
 }