File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,36 @@ def fix_replication_from_slow_query_log_after_upgrade():
36
36
run_mysql_command ("START SLAVE;" )
37
37
run_mysql_command ("SET GLOBAL slow_query_log = 'ON';" )
38
38
run_mysql_command ("show slave status\G;" )
39
+
40
+
41
+ @task
42
+ def setup_slave_from_master (master ):
43
+ """
44
+ Sets up a slave from a master by taking a dump from the master,
45
+ copying it to the slave and then restoring the dump.
46
+
47
+ Usage: fab environment -H mysql-slave-1.backend mysql.setup_slave_from_master:'mysql-master-1.backend'
48
+ """
49
+ if len (env .hosts ) > 1 :
50
+ print 'This job is currently only setup to run against one slave at a time'
51
+
52
+ with settings (host_string = master ):
53
+ # The use of `--master-data` here implies `--lock-all-tables` per the
54
+ # MySQL reference manual: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_master-data
55
+ run ('sudo -i mysqldump -u root --all-databases --master-data --add-drop-database > dump.sql' )
56
+
57
+ with settings (host_string = master , forward_agent = True ):
58
+ run ('scp dump.sql {0}:~' .format (env .hosts [0 ]))
59
+
60
+ with settings (host_string = master ):
61
+ run ('rm dump.sql' )
62
+
63
+ run_mysql_command ("STOP SLAVE" )
64
+ run_mysql_command ("SET GLOBAL slow_query_log=OFF" )
65
+
66
+ run ('sudo -i mysql -uroot < dump.sql' )
67
+
68
+ run_mysql_command ("START SLAVE" )
69
+ run_mysql_command ("SET GLOBAL slow_query_log=ON" )
70
+
71
+ run_mysql_command ("SHOW SLAVE STATUS\G" )
You can’t perform that action at this time.
0 commit comments