-
Notifications
You must be signed in to change notification settings - Fork 1
/
move_dumps.php
62 lines (57 loc) · 1.79 KB
/
move_dumps.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include './archive_common.php.inc';
$baseDir = '/var/www/httparchive.dev/downloads';
if (is_file("$baseDir/archived.json")) {
$downloads = json_decode(file_get_contents("$baseDir/archived.json"), true);
}
if (!isset($downloads) || !is_array($downloads)) {
exit(0);
}
// Go through the existing dumps and move them to gcs
foreach($downloads as $filename => &$download) {
$parts = parse_url($download['url']);
$host = $parts['host'];
$path = '/var/www/wptarchive/' . $filename;
if( $host != "storage.googleapis.com") {
if (download($download['url'], $path)) {
if (is_file($path)) {
if (gsUpload($path)) {
$downloads[$filename] =
array('url' => "https://storage.googleapis.com/httparchive/downloads/$filename",
'size' => $size,
'modified' => $modified,
'verified' => true,
'bucket' => 'httparchive');
file_put_contents("$baseDir/archived.json", json_encode($downloads));
}
}
}
}
}
function download($url, $path) {
$ret = false;
echo("Downloading $url to $path\n");
$command = "wget \"$url\" -O \"$path\"";
echo($command . "\n");
exec($command, $output, $result);
if ($result == 0) {
$ret = true;
echo("Download Complete\n");
} else {
echo("Download Failed\n");
}
return $ret;
}
function gsUpload($file) {
$ret = false;
echo("Uploading $file to gs://httparchive/$crawlName\n");
exec("gsutil -m mv \"$file\" gs://httparchive/downloads/", $output, $result);
if ($result == 0) {
$ret = true;
echo("Upload Complete\n");
} else {
echo("Upload Failed\n");
}
return $ret;
}
?>