-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuslims_update_notice.php
86 lines (69 loc) · 2.09 KB
/
uslims_update_notice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
$self = __FILE__;
$hdir = __DIR__;
$us3bin = exec( "ls -d ~us3/lims/bin" );
include_once "$us3bin/listen-config.php";
# to enable new remote database
# grant select, show view on us3_notice.* to us3_notice@'%' identified by 'us3_notice'
$notes = <<<__EOD
usage: $self {config_file}
syncs us3_notice from localhost to remote host
// needs keys setup
1. mysqldump of us3_notice
2 scp? (or can we use a local file into an ssh command as input?
3. ssh mysql --defaults-file=\$remote... -u ? import
__EOD;
$u_argv = $argv;
array_shift( $u_argv );
if ( count( $u_argv ) > 1 ) {
echo $notes;
exit;
}
$config_file = "$hdir/db_config.php";
if ( count( $u_argv ) ) {
$use_config_file = array_shift( $u_argv );
} else {
$use_config_file = $config_file;
}
if ( !file_exists( $use_config_file ) ) {
fwrite( STDERR, "$self:
$use_config_file does not exist
to fix:
cp ${config_file}.template $use_config_file
and edit with appropriate values
")
;
exit(-1);
}
if ( count( $u_argv ) ) {
echo $notes;
exit;
}
include "utility.php";
file_perms_must_be( $use_config_file );
require $use_config_file;
$myconf = "$hdir/my.cnf";
if ( !file_exists( $myconf ) ) {
error_exit(
"create a file '$myconf' in the $hdir directory with the following contents:\n"
. "[mysqldump]\n"
. "password=YOUR_ROOT_DB_PASSWORD\n"
. "max_allowed_packet=256M\n"
);
}
file_perms_must_be( $myconf );
$errors = "";
if ( !isset( $notice_remote_host ) ) {
$errors .= "\$notice_remote_host is not set in $use_config_file\n";
}
if ( !isset( $notice_remote_user ) ) {
$errors .= "\$notice_remote_user is not set in $use_config_file\n";
}
if ( !isset( $notice_remote_db_user ) ) {
$errors .= "\$notice_remote_user is not set in $use_config_file\n";
}
if ( strlen( $errors ) ) {
error_exit( $errors );
}
$cmd = "mysqldump --defaults-file=$myconf -u us3_notice us3_notice notice | ssh $notice_remote_user@$notice_remote_host mysql --defaults-file=$notice_remote_mycnf -u $notice_remote_db_user us3_notice";
run_cmd( $cmd );