1# ==== Purpose ====
2#
3# Relocates the relay logs and index file from
4# a directory into another. The logs relocated
5# are the one listed in the index file.
6#
7# ==== Usage ====
8#
9# [--let $relocate_disable_query_log= 1]
10# [--let $rpl_debug= 1]
11# [--let $relocate_is_windows= 0]
12# [--let $relocate_recreate_index= 0]
13# [--let $relocate_fix_relay_log_info= 0]
14# --let $relocate_from= DIR
15# --let $relocate_to= DIR
16# --let $relocate_index_file= FNAME
17# --source include/relocate_binlogs.inc
18
19if ($relocate_disable_query_log)
20{
21  --disable_query_log
22}
23
24--let $_path_separator=/
25if ($relocate_is_windows)
26{
27  --let $_path_separator=\
28}
29
30if ($relocate_index_file)
31{
32  SET SQL_LOG_BIN=0;
33  CREATE TEMPORARY TABLE tmp(id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(1024));
34
35  --let $write_var=
36  --let $_index_file= $relocate_index_file
37  --let $_index_file_basename= `SELECT RIGHT(RTRIM("$_index_file"), LOCATE("$_path_separator",REVERSE(RTRIM("$_index_file"))) -1)`
38  --let $_from= $relocate_from
39  --let $_to= $relocate_into
40
41  # chmod to allow the following LOAD DATA
42  --chmod 0666 $_index_file
43
44  --eval LOAD DATA INFILE '$_index_file' INTO TABLE tmp (filename)
45  --let $count= `SELECT count(*) FROM tmp`
46
47  while ($count)
48  {
49    --let $_filename= `select filename from tmp where id=$count`
50
51    --let $_filename= `SELECT RIGHT(RTRIM("$_filename"), LOCATE("$_path_separator",REVERSE(RTRIM("$_filename"))) -1)`
52    --move_file $_from/$_filename $_to/$_filename
53
54    if ($relocate_recreate_index)
55    {
56
57      if ($relocate_is_windows)
58      {
59        --let $_write_var=$_to\$_filename\n
60      }
61      if (!$relocate_is_windows)
62      {
63        --let $_write_var=$_to/$_filename\n
64      }
65      if (!$write_var)
66      {
67        --let $write_var=$_write_var
68      }
69
70      if (!`SELECT STRCMP('$write_var', '$_write_var') = 0`)
71      {
72        --let $write_var=$_write_var$write_var
73      }
74    }
75
76    --dec $count
77  }
78
79  if (!$relocate_recreate_index)
80  {
81    --move_file $_index_file $_to/$_index_file_basename
82  }
83
84  if ($relocate_recreate_index)
85  {
86    --let $write_to_file= $_to/$_index_file_basename
87    --source include/write_var_to_file.inc
88    --remove_file $_index_file
89  }
90
91  DROP TEMPORARY TABLE tmp;
92
93  if ($relocate_fix_relay_log_info)
94  {
95    CREATE TEMPORARY TABLE tmp(id INT AUTO_INCREMENT PRIMARY KEY, entry VARCHAR(1024));
96    --let $write_var=
97
98    # chmod to allow the following LOAD DATA
99    --chmod 0666 $relocate_fix_relay_log_info
100
101    --eval LOAD DATA INFILE '$relocate_fix_relay_log_info' INTO TABLE tmp (entry)
102    --let $count= `SELECT count(*) FROM tmp`
103
104    --let $_curr_entry= `SELECT entry FROM tmp WHERE id=2`
105    --let $_curr_entry_basename= `SELECT RIGHT(RTRIM("$_curr_entry"), LOCATE("$_path_separator",REVERSE(RTRIM("$_curr_entry"))) -1)`
106
107    if ($relocate_is_windows)
108    {
109      --eval UPDATE tmp SET entry='$_to\$_curr_entry_basename' WHERE id=2
110    }
111    if (!$relocate_is_windows)
112    {
113      --eval UPDATE tmp SET entry='$_to/$_curr_entry_basename' WHERE id=2
114    }
115
116    --remove_file $relocate_fix_relay_log_info
117
118    while($count)
119    {
120      --let $_write_var= `SELECT entry FROM tmp WHERE id= $count`
121      --let $write_var=$_write_var\n$write_var
122      --dec $count
123    }
124
125    --let $write_to_file= $relocate_fix_relay_log_info
126    --source include/write_var_to_file.inc
127
128    DROP TEMPORARY TABLE tmp;
129  }
130  SET SQL_LOG_BIN=1;
131}
132
133
134if ($relocate_disable_query_log)
135{
136  --enable_query_log
137}
138