Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. *DB Slave:*
  2. ```
  3. ##Backup grants
  4. # mysql -B -N -e "SELECT DISTINCT CONCAT('SHOW GRANTS FOR \'', user, '\'@\'', host, '\';') AS query FROM mysql.user" | mysql | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' | grep ^GRANT > /root/grants_2016-11-21.sql
  5.  
  6. ##Stop MySQL
  7. # systemctl stop mysql
  8.  
  9. ##Enable root login on ssh
  10. # echo "PermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd
  11.  
  12. ##Remove mysql data
  13. # rm -rf /mysql/data/*
  14.  
  15. ##Install xtrabackup
  16. # yum install percona-xtrabackup
  17. ```
  18.  
  19. *DB Master:*
  20. ```
  21. ##Create temporary ssh key
  22. # ssh-keygen -f /root/.ssh/replication_tmp
  23.  
  24. ##Copy public key to slave server
  25. # cat /root/.ssh/replication_tmp.pub (Colocar manualmente no /root/.ssh/authorized_keys do slave alvo)
  26.  
  27. ##Disable slave_parallel_workers if enabled
  28. # mysql -e "SET GLOBAL slave_parallel_workers=0;"
  29.  
  30. ##Streaming data from master to slave server
  31. # time xtrabackup --user=root --password=xxxxxxxxx --host=127.0.0.1 --stream=xbstream --backup | ssh -i /root/.ssh/replication_tmp root@slave_ip "xbstream -x -C /mysql/data"
  32.  
  33. ##Create replication grant to MySQL slave
  34. # mysql -e "GRANT REPLICATION SLAVE ON *.* TO 'replicator-dbX'@'slave_ip' IDENTIFIED BY 'myReplicatorPassword';"
  35.  
  36. ##Remove temporary ssh keys
  37. # rm -rf /root/.ssh/replication_tmp*
  38. ```
  39.  
  40. *DB Slave:*
  41. ```
  42. ##Prepare the data to a consistent snapshot (apply logs)
  43. # time xtrabackup --prepare --target-dir=/mysql/data
  44.  
  45. ##Change owner to the mysql user
  46. # chown -R mysql. /mysql/data
  47.  
  48. ##Start MySQL
  49. # systemctl start mysql
  50.  
  51. ##Drop all non-root grants and users
  52. # mysql -B -N -e "SELECT DISTINCT CONCAT('DROP USER \'', user, '\'@\'', host, '\';') AS query FROM mysql.user where user <> 'root'" | mysql
  53.  
  54. ##Import grants from backup
  55. # mysql < /root/grants_2016-11-21.sql
  56.  
  57. ##Getting binlog possition
  58. # cat /mysql/data/cat xtrabackup_binlog_info
  59.  
  60. ##Settigup parameters of MySQL slave
  61. # mysql -e "CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_PORT=3306, MASTER_USER='replicator-dbX', MASTER_PASSWORD='myReplicatorPassword', MASTER_LOG_FILE='mysql-bin.006653', MASTER_LOG_POS=184143837;"
  62.  
  63. ##Start MySQL Slave
  64. # mysql -e "start slave;"
  65.  
  66. ##Watching the MySQL slave status
  67. # watch "mysql -e 'show slave status\G'"
  68.  
  69. ##Disable root login on ssh
  70. # sed -i '/PermitRootLogin yes/d' /etc/ssh/sshd_config; systemctl restart sshd
  71. ```
  72.  
  73. *Replica-AWS*
  74. ```
  75. ##Backup of unreplicated schemas (Check if no new schemas non-replicated have been created)
  76. # for DB in archiving bi bob_bak bob_live2 bob_migration catalog_clean cleanup diff report temp test trash xhprof; do echo "dumping ${DB}; "mysqldump --opt --single-transaction ${DB} | gzip > /reports/${DB}.sql.gz ; done
  77.  
  78. ## Do the restore process
  79.  
  80. ##Restore of unreplicated schemas
  81. # for DB in archiving bi bob_bak bob_live2 bob_migration catalog_clean cleanup diff report temp test trash xhprof; do echo "Restoring ${DB}"; mysql -e "create database ${DB};" ;pv -p -t -e /reports/${DB}.sql.gz | gzip -d -c - | mysql ${DB} ; done
  82. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement