Move TYPO3 media to external volume

Sometimes over the time, when more and more projects is coming to SSD disk the space is in slowly ending. On MacBook there is SD slot which can help us to extend harddrive possibilitues and move to this SD a files that do not need to be read fast – typically media files. For TYPO3 projects its fileadmin and uploads folders.

Below you will find a php script which will move fileadmin/ and uploads/ folder to external drive and make a symlink to moved folder. Put this script inside folder with all your TYPO3 projects. Change $externalVolumePath to your external volume with the name of folder you want to store the projects with media files. Make a first run with $dry = true; It will allow you to see the commands that will be executed. Then change to  $dry = false;

<?php

// directory names without(!) ending slash
$externalVolumePath = '/Volumes/Media/projects_media/typo3';
$mediaDirsToMakeSymlink = [
    'fileadmin',
    'files',
    'uploads',
    '.deploy/database/dumps'
];
$dry = 0;



// DO NOT MODIFY BELOW

if(is_dir($externalVolumePath)) {
    $i = 1;

    foreach (glob(__DIR__ . "/*", GLOB_ONLYDIR) as $project) {
        $projectName = end(explode('/', $project));
        foreach($mediaDirsToMakeSymlink as $mediaDirToMakeSymlink) {
            $mediaDirToMakeSymlink = rtrim($mediaDirToMakeSymlink, '/');
            $sourceDirToSymlink = $project . '/' . $mediaDirToMakeSymlink;
            if(!is_dir($externalVolumePath . '/' . $projectName . '/' . $mediaDirToMakeSymlink) && is_dir($sourceDirToSymlink)) {
                @mkdir($externalVolumePath . '/' . $projectName . '/' . $mediaDirToMakeSymlink, 0755, true);
                $command = "mv '" . $sourceDirToSymlink . "/' '" . $externalVolumePath . "/" . $projectName . "/" . ((dirname($mediaDirToMakeSymlink) == ".") ? "" : dirname($mediaDirToMakeSymlink))  . "'"
;
                if(!$dry) {
                        exec($command);
                }
                echo($command . "\n");

                $command = "ln -s '" . $externalVolumePath . "/" . $projectName . "/" . $mediaDirToMakeSymlink . "' '" . $sourceDirToSymlink . "'";
                if(!$dry) {
                        exec($command);
                }
                echo($command . "\n");
            }
        }
        $i++;
    }
} else {
    die('$externalVolumePath is not a dir!');
}

 

 

Disabling Spotlight / Trashes

mdutil -i off /Volumes/Media
cd /Volumes/Media
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index .Trashes

 

Leave a Comment.