Added logging if blob download encounters errors. Add bulk download script. #551
This commit is contained in:
parent
b2e23e8ed9
commit
f96540253a
2 changed files with 67 additions and 5 deletions
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// NOTE: reference: https://github.com/Azure/azure-storage-php/blob/master/samples/BlobSamples.php
|
||||||
|
|
||||||
|
require_once(__DIR__ . '/../../vendor/autoload.php');
|
||||||
|
|
||||||
|
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
|
||||||
|
use MicrosoftAzure\Storage\Common\ServiceException;
|
||||||
|
|
||||||
|
//$blob_url = 'https://popappshopprodstorage.blob.core.windows.net/warranty';
|
||||||
|
//$sas_token = 'sp=r&st=2021-03-18T08:26:36Z&se=2021-04-29T16:26:36Z&spr=https&sv=2020-02-10&sr=c&sig=Rwl3aCNThXEzuPjNB9sTvZzsx84ULDylyS1WtPwgyzg%3D';
|
||||||
|
|
||||||
|
|
||||||
|
$blob_url = 'https://popappshopprodstorage.blob.core.windows.net';
|
||||||
|
//$sas_token = 'sp=r&st=2021-03-20T17:09:13Z&se=2021-04-01T01:09:13Z&spr=https&sv=2020-02-10&sr=c&sig=pU2fxj6eXALfGTTrsmaJ7W0QtdstyR88Xs5lvMJ35xQ%3D';
|
||||||
|
|
||||||
|
$sas_token = 'sp=r&st=2021-04-13T03:48:30Z&se=2022-04-01T11:48:30Z&spr=https&sv=2020-02-10&sr=c&sig=L6VDl40qRXhQb7w8JVkj3r7x2Xkt72pQaQ8AH2M5CRk%3D';
|
||||||
|
|
||||||
|
$conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token";
|
||||||
|
|
||||||
|
$blob_client = BlobRestProxy::createBlobService($conn_string);
|
||||||
|
|
||||||
|
// get start date from argument: 04-01-21 format
|
||||||
|
$start_date = $argv[1];
|
||||||
|
|
||||||
|
$current_date = new DateTime();
|
||||||
|
|
||||||
|
$end_date = $current_date->format('m-d-y');
|
||||||
|
|
||||||
|
$flag_done_processing = false;
|
||||||
|
$proc_date = $start_date;
|
||||||
|
|
||||||
|
while (!$flag_done_processing) {
|
||||||
|
$filename = 'warrantylogs' . $proc_date . '.csv';
|
||||||
|
echo $filename, PHP_EOL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// NOTE: via download blob
|
||||||
|
$res = $blob_client->getBlob('warranty', $filename);
|
||||||
|
// print_r($res);
|
||||||
|
|
||||||
|
file_put_contents("/tmp/output.txt", $res->getContentStream(), FILE_APPEND);
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// change proc_date to next day
|
||||||
|
$next_date = DateTime::createFromFormat('m-d-y', $proc_date);
|
||||||
|
$next_date->modify('+1 day');
|
||||||
|
$proc_date = $next_date->format('m-d-y');
|
||||||
|
|
||||||
|
if ($end_date == $proc_date) {
|
||||||
|
$flag_done_processing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -26,13 +26,18 @@ $current_date->modify("-1 day");
|
||||||
$date = $current_date->format('m-d-y');
|
$date = $current_date->format('m-d-y');
|
||||||
|
|
||||||
$filename = 'warrantylogs' . $date . '.csv';
|
$filename = 'warrantylogs' . $date . '.csv';
|
||||||
print_r($filename);
|
//print_r($filename);
|
||||||
|
|
||||||
|
try {
|
||||||
// NOTE: via download blob
|
// NOTE: via download blob
|
||||||
$res = $blob_client->getBlob('warranty', $filename);
|
$res = $blob_client->getBlob('warranty', $filename);
|
||||||
// print_r($res);
|
// print_r($res);
|
||||||
|
|
||||||
file_put_contents("/tmp/output.txt", $res->getContentStream());
|
file_put_contents("/tmp/output.txt", $res->getContentStream());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// NOTE: getting via url
|
// NOTE: getting via url
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue