Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!perl -w
- use utf8;
- use POSIX;
- use 5.10.0;
- use YAML::Tiny;
- use Try::Tiny;
- my $yaml = YAML::Tiny->read($ARGV[0]);
- exit $ARGV[0];
- my $config = $yaml->[0];
- try {
- print 'Sync files...';
- `rsync --exclude wp-config.php --exclude .htaccess -av --log-file=../sync_log.log $config->{local}->{path}/* $config->{remote}->{host}:$config->{remote}->{path}`;
- print 'Done', "\n";
- } catch {
- exit 'Error: '.$!;
- }
- try {
- print 'Dumping local database...';
- `mysqldump -h $config->{local}->{db_host} -u $config->{local}->{db_user} -p'$config->{local}->{db_passwd}' --databases $config->{local}->{db_name} > $config->{local}->{db_name}.sql`;
- print 'Done',"\n";
- } catch {
- exit 'Error: '.$!;
- }
- try {
- print 'Replacements...';
- `sed -i 's/$config->{local}->{regex_url}/$config->{remote}->{regex_url}/g' $config->{local}->{db_name}.sql`;
- print 'Done',"\n";
- } catch {
- exit 'Error: '.$!;
- }
- try {
- print 'Sync Database in remote host...';
- `mysql -h $config->{remote}->{db_host} -u $config->{remote}->{db_user} -p'$config->{remote}->{db_passwd}' < $config->{remote}->{db_name}.sql`;
- print 'Done',"\n";
- }
- catch {
- exit 'Error: '.$!;
- }
- print "Migration completed!!";
- __DATA__
- Example of config.yaml
- USAGE perl siteSync.pl config.yaml
- ----
- local:
- localpath: ''
- db_host
- db_user: ''
- db_passwd: ''
- db_name: ''
- regex_url: ''
- remote:
- host: ''
- path: ''
- db_host
- db_user: ''
- db_passwd: ''
- db_name: ''
- regex_url:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement