Parse platform 将解析文件从Gridstore迁移到S3

Parse platform 将解析文件从Gridstore迁移到S3,parse-platform,Parse Platform,我们将数据(无文件)迁移到mLab和Heroku。因此,旧文件仍处于解析状态 从那时起,添加的任何新文件都会进入Gridstore,这是mLab的默认文件存储 现在,我使用 文件已迁移,可使用Heroku中的S3Adapter访问 但是,Gridstore上的文件现在无法访问。如何将它们迁移到相同的S3 bucket并更改mLab中的引用?也许您对我尝试过的解决方案感兴趣。这不是一个简单的操作,但我使用解析服务器配置成功迁移了3个数据库 它基于一个贯穿每个对象的PHP脚本(带有Parse PHP

我们将数据(无文件)迁移到mLabHeroku。因此,旧文件仍处于解析状态

从那时起,添加的任何新文件都会进入Gridstore,这是mLab的默认文件存储

现在,我使用

文件已迁移,可使用Heroku中的S3Adapter访问


但是,Gridstore上的文件现在无法访问。如何将它们迁移到相同的S3 bucket并更改mLab中的引用?

也许您对我尝试过的解决方案感兴趣。这不是一个简单的操作,但我使用解析服务器配置成功迁移了3个数据库

它基于一个贯穿每个对象的PHP脚本(带有Parse PHP SDK),它从Parse.com获取文件并在您自己的服务器中设置它(使用任何适配器配置)

脚本如下所示:

<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    date_default_timezone_set('America/New_York');
    
    $fileField = $argv[1];
    $class     = $argv[2];
    
    require_once 'vendor/autoload.php';
    use Parse\ParseObject;
    use Parse\ParseQuery;
    use Parse\ParseACL;
    use Parse\ParsePush;
    use Parse\ParseUser;
    use Parse\ParseInstallation;
    use Parse\ParseException;
    use Parse\ParseAnalytics;
    use Parse\ParseFile;
    use Parse\ParseCloud;
    use Parse\ParseClient;
    
    $app_id     = "******";
    $rest_key   = "******";
    $master_key = "******";
    
    ParseClient::initialize($app_id, $rest_key, $master_key);
    ParseClient::setServerURL('http://localhost:1338/', 'parse');
    
    $query = new ParseQuery($class);
    $query->ascending("createdAt"); // it's just my preference
    $query->exists($fileField);
    $query->limit(1);
    
    $count = $query->count();
    for ($i = 0; $i < $count; $i = $i + 1) {
        try {
            $query->skip($i);
            // get Entry
            $entryWithFile = $query->first();
            
            // get file
            $parseFile = $entryWithFile->get($fileField);
            // filename
            $fileName  = $parseFile->getName();

            // if the file is hosted in Parse, do the job, otherwise continue with the next one
            if (strpos($fileName, "tfss-") === false) {
                echo "\nThis is already an internal file, skipping...";
                continue;
            }
            
            $newFileName = str_replace("tfss-", "", $fileName);
            $binaryFile  = file_get_contents($parseFile->getURL());
            
            $newFile = ParseFile::createFromData($binaryFile, $newFileName);
            
            $entryWithFile->set($fileField, $newFile);
            $entryWithFile->save(true);
            
            echo "\nFile saved\n";
        }
        catch (Exception $e) {
            // The conection with mongo or the server could be off for some second, let's retry it ;)
            sleep(10);
            continue;
        }
    }
    
    echo "\n";
    echo "END!";
    
?>
因此,如果您像以前一样配置
$fileField
$class
,并且可以打开3个线程并运行:

php migrator.php 0 3“imageProfile”“\u User”

php migrator.php 13“imageProfile”“\u User”

php migrator.php 23“imageProfile”“\u User”

因此,循环的运行方式如下:

对象0、3、6

对象1、4、7

对象2、5、8

祝你好运,快点!几天后它就要关闭了

<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    date_default_timezone_set('America/New_York');
    
    $index     = $argv[1];
    $of        = $argv[2];
    $fileField = $argv[3];
    $class     = $argv[4];
    
    require_once 'vendor/autoload.php';
    use Parse\ParseObject;
    use Parse\ParseQuery;
    use Parse\ParseACL;
    use Parse\ParsePush;
    use Parse\ParseUser;
    use Parse\ParseInstallation;
    use Parse\ParseException;
    use Parse\ParseAnalytics;
    use Parse\ParseFile;
    use Parse\ParseCloud;
    use Parse\ParseClient;
    
    $app_id     = "********";
    $rest_key   = "********";
    $master_key = "********";
    
    ParseClient::initialize($app_id, $rest_key, $master_key);
    ParseClient::setServerURL('http://localhost:1338/', 'parse');
    
    $query = new ParseQuery($class);
    $query->ascending("createdAt");
    $query->exists($fileField);
    $query->limit(1);
    
    $count = $query->count();
    for ($i = $index; $i < $count; $i = $i + $of) {
        try {
            $query->skip($i);
            // get Entry
            $entryWithFile = $query->first();
            
            // get file
            $parseFile = $entryWithFile->get($fileField);
            // filename
            $fileName  = $parseFile->getName();

            // if the file is hosted in Parse, do the job, otherwise continue with the next one
            if (strpos($fileName, "tfss-") === false) {
                echo "\nThis is already an internal file, skipping...";
                continue;
            }
            
            $newFileName = str_replace("tfss-", "", $fileName);
            $binaryFile  = file_get_contents($parseFile->getURL());
            
            $newFile = ParseFile::createFromData($binaryFile, $newFileName);
            
            $entryWithFile->set($fileField, $newFile);
            $entryWithFile->save(true);
            
            echo "\nFile saved\n";
        }
        catch (Exception $e) {
            // The conection with mongo or the server could be off for some second, let's retry it ;)
            sleep(10);
            continue;
        }
    }
    
    echo "\n";
    echo "END!";
    
?>