mDescription = "Copy all the files in one backend to another."; $this->addOption( 'src', 'Backend containing the source files', true, true ); $this->addOption( 'dst', 'Backend where files should be copied to', true, true ); $this->addOption( 'containers', 'Pipe separated list of containers', true, true ); $this->addOption( 'fast', 'Skip SHA-1 checks on pre-existing files' ); } public function execute() { $src = FileBackendGroup::singleton()->get( $this->getOption( 'src' ) ); $dst = FileBackendGroup::singleton()->get( $this->getOption( 'dst' ) ); $containers = explode( '|', $this->getOption( 'containers' ) ); foreach ( $containers as $container ) { $this->output( "Doing container $container...\n" ); $srcPathsRel = $src->getFileList( array( 'dir' => $src->getRootStoragePath() . "/$container" ) ); if ( $srcPathsRel === null ) { $this->error( "Could not list files in $container.", 1 ); // die } foreach ( $srcPathsRel as $srcPathRel ) { $srcPath = $src->getRootStoragePath() . "/$container/$srcPathRel"; $dstPath = $dst->getRootStoragePath() . "/$container/$srcPathRel"; if ( $dst->fileExists( array( 'src' => $dstPath, 'latest' => 1 ) ) ) { if ( $this->hasOption( 'fast' ) ) { $this->output( "Already have $dstPath.\n" ); continue; // assume already copied... } $srcSha1 = $src->getFileSha1Base36( array( 'src' => $srcPath ) ); $dstSha1 = $dst->getFileSha1Base36( array( 'src' => $dstPath ) ); if ( $srcSha1 && $srcSha1 === $dstSha1 ) { $this->output( "Already have $dstPath.\n" ); continue; // already copied... } } $fsFile = $src->getLocalReference( array( 'src' => $srcPath, 'latest' => 1 ) ); if ( !$fsFile ) { $this->error( "Could not get local copy of $srcPath.", 1 ); // die } $status = $dst->prepare( array( 'dir' => dirname( $dstPath ) ) ); $status->merge( $dst->store( array( 'src' => $fsFile->getPath(), 'dst' => $dstPath ), array( 'nonLocking' => 1, 'nonJournaled' => 1 ) ) ); if ( !$status->isOK() ) { print_r( $status->getErrorsArray() ); $this->error( "Could not copy $srcPath to $dstPath.", 1 ); // die } $this->output( "Copied $srcPath to $dstPath.\n" ); } } } } $maintClass = 'CopyFileBackend'; require_once( RUN_MAINTENANCE_IF_MAIN );