Skip to content

Commit 079620a

Browse files
committed
Support restoring from gcloud
1 parent 0bfd28d commit 079620a

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

www/archive.inc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,22 @@ function RestoreArchive($id)
334334
GetSetting('archive_dir') ||
335335
GetSetting('archive_url') ||
336336
GetSetting('archive_s3_url') ||
337-
GetSetting('archive_s3_server')
337+
GetSetting('archive_s3_server') ||
338+
GetSetting('archive_gcloud_path')
338339
) {
339340
$deleteZip = true;
340341
$do_not_download = false;
341342
$zipfile = "./tmp/$id.zip";
342-
if ($capture_server && $capture_salt) {
343+
if (GetSetting('archive_gcloud_path')) {
344+
putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ ."/settings/application_default_credentials.ini");
345+
$gcloud_path = GetSetting('archive_gcloud_path');
346+
$command = "gcloud storage cp $gcloud_path/$id.zip $zipfile 2>&1";
347+
$output = shell_exec($command);
348+
$archive_log = GetSetting('archive_log');
349+
if ($archive_log) {
350+
error_log(gmdate('Y/m/d H:i:s - ') . "$id - $command - $output\n", 3, $archive_log);
351+
}
352+
} else if ($capture_server && $capture_salt) {
343353
$do_not_download = true;
344354
$host = str_replace('.', '', trim(GetSetting('host')));
345355
$cpid = GetCPID($host, $capture_salt);

www/common_lib.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,14 @@ function RestoreTest($id)
13001300
$archive_url = GetSetting('archive_url');
13011301
$archive_s3_url = GetSetting('archive_s3_url');
13021302
$archive_s3_server = GetSetting('archive_s3_server');
1303+
$gcloud_path = GetSetting('archive_gcloud_path');
13031304
if (
13041305
($capture_server && $capture_salt) ||
13051306
($archive_dir && strlen($archive_dir)) ||
13061307
($archive_url && strlen($archive_url)) ||
13071308
($archive_s3_url && strlen($archive_s3_url)) ||
1308-
($archive_s3_server && strlen($archive_s3_server))
1309+
($archive_s3_server && strlen($archive_s3_server)) ||
1310+
($gcloud_path && strlen($gcloud_path))
13091311
) {
13101312
$ret = RestoreArchive($id);
13111313
} else {

0 commit comments

Comments
 (0)