Advertisement
kwasinski

Migrate WP SITE

May 22nd, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.46 KB | None | 0 0
  1. #!perl -w
  2.  
  3. use utf8;
  4. use POSIX;
  5. use 5.10.0;
  6.  
  7. use YAML::Tiny;
  8. use Try::Tiny;
  9.  
  10. my $yaml = YAML::Tiny->read($ARGV[0]);
  11. exit $ARGV[0];
  12. my $config = $yaml->[0];
  13.  
  14. try {
  15.     print 'Sync files...';
  16.     `rsync --exclude wp-config.php --exclude .htaccess  -av --log-file=../sync_log.log  $config->{local}->{path}/* $config->{remote}->{host}:$config->{remote}->{path}`;
  17.     print 'Done', "\n";
  18. } catch {
  19.     exit 'Error: '.$!;
  20. }
  21.  
  22. try {
  23.     print 'Dumping local database...';
  24.     `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`;
  25.     print 'Done',"\n";
  26. } catch {
  27.     exit 'Error: '.$!;
  28. }
  29.  
  30. try {
  31.     print 'Replacements...';
  32.     `sed -i 's/$config->{local}->{regex_url}/$config->{remote}->{regex_url}/g' $config->{local}->{db_name}.sql`;
  33.     print 'Done',"\n";
  34. } catch {
  35.     exit 'Error: '.$!;
  36. }
  37.  
  38.  
  39. try {
  40.     print  'Sync Database in remote host...';
  41.     `mysql -h $config->{remote}->{db_host} -u $config->{remote}->{db_user} -p'$config->{remote}->{db_passwd}' < $config->{remote}->{db_name}.sql`;
  42.     print 'Done',"\n";
  43. }
  44. catch {
  45.     exit 'Error: '.$!;
  46.  
  47. }
  48.  
  49. print "Migration completed!!";
  50.  
  51.  
  52. __DATA__
  53.  
  54. Example of config.yaml
  55.  
  56. USAGE perl siteSync.pl config.yaml
  57. ----
  58. local:
  59.     localpath: ''
  60.     db_host
  61.     db_user: ''
  62.     db_passwd: ''
  63.     db_name: ''
  64.     regex_url: ''
  65.  
  66. remote:
  67.     host: ''
  68.     path: ''
  69.     db_host
  70.     db_user: ''
  71.     db_passwd: ''
  72.     db_name: ''
  73.     regex_url:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement