Last active
April 26, 2017 16:33
-
-
Save treetop1500/175de553766679f3447c3fb5733127e0 to your computer and use it in GitHub Desktop.
Rsync Console Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by rwade@grayloon.com | |
* User: rwade | |
* Date: 4/26/17 | |
* Time: 9:53 AM | |
* @todo update output to be buffered realtime output | |
* @todo colored output | |
*/ | |
namespace AppBundle\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Input\InputArgument; | |
/** | |
* Class RsyncCommand | |
* @package AppBundle\Command | |
*/ | |
class RsyncCommand extends Command | |
{ | |
/** | |
* Configure the Command Defaults | |
*/ | |
protected function configure() | |
{ | |
$this | |
// the name of the command (the part after "bin/console") | |
->setName('app:rsync') | |
// the short description shown while running "php bin/console list" | |
->setDescription('Rsyncs files between production and development') | |
->addArgument('direction', InputArgument::REQUIRED, 'The direction to rsync. Options are "to" or "from" production.') | |
// the full command description shown when running the command with | |
// the "--help" option | |
->setHelp('Allows you to rsync files from development to production and vice versa'); | |
} | |
/** | |
* @param InputInterface $input | |
* @param OutputInterface $output | |
* @return void | |
*/ | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
// outputs multiple lines to the console (adding "\n" at the end of each line) | |
$output->writeln([ | |
'=====================================', | |
'Rsync Files '.$input->getArgument('direction').' production', | |
'', | |
]); | |
// update "host" and local directories: | |
if ($input->getArgument('direction') == 'to') { | |
exec('rsync -r /Apache/sites/client/client.com/web/uploads host:web/ --progress', $op); | |
} elseif ($input->getArgument('direction') == 'from') { | |
exec('rsync -r host:web/uploads /Apache/sites/client/client.com/web/ --progress', $op); | |
} else { | |
$output->writeln('Error! Direction argument not provided. Use "to" or "from".'); | |
} | |
// outputs a message followed by a "\n" | |
$output->writeln($op); | |
// outputs a message followed by a "\n" | |
$output->writeln([ | |
'', | |
'Rsync Complete', | |
'=====================================', | |
'', | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment