/usr/bin/mysqluserclone is in mysql-utilities 1.0.5-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #!/usr/bin/python
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
"""
This file contains the clone user utility. It is used to clone an existing
MySQL user to one or more new user accounts copying all grant statements
to the new users.
"""
import optparse
import os.path
import sys
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.options import parse_connection
from mysql.utilities.common.options import add_verbosity, check_verbosity
from mysql.utilities.common.options import add_format_option
from mysql.utilities.exception import UtilError
from mysql.utilities.command import userclone
from mysql.utilities import VERSION_FRM
# Constants
NAME = "MySQL Utilities - mysqluserclone "
DESCRIPTION = "mysqluserclone - clone a MySQL user account to" + \
" one or more new users"
USAGE = "%prog --source=user:pass@host:port:socket " \
"--destination=user:pass@host:port:socket " \
"joe@localhost sam:secret1@localhost"
# Setup the command parser
parser = setup_common_options(os.path.basename(sys.argv[0]),
DESCRIPTION, USAGE, True, False)
# Setup utility-specific options:
# Connection information for the source server
parser.add_option("--source", action="store", dest="source",
type = "string", default="root@localhost:3306",
help="connection information for source server in " + \
"the form: <user>:<password>@<host>:<port>:<socket>")
# Connection information for the destination server
parser.add_option("--destination", action="store", dest="destination",
type = "string",
help="connection information for destination server in " + \
"the form: <user>:<password>@<host>:<port>:<socket>")
# Dump mode
parser.add_option("-d", "--dump", action="store_true",
dest="dump", help="dump GRANT statements for user - does "
"not require a destination")
# Overwrite mode
parser.add_option("--force", action="store_true", dest="overwrite",
help="drop the new user if it exists")
# Include globals mode
parser.add_option("--include-global-privileges", action="store_true",
dest="global_privs", help="include privileges that match "
"base_user@% as well as base_user@host", default=False)
# List mode
parser.add_option("--list", action="store_true", dest="list_users",
help="list all users on the source - does not require "
"a destination", default=False)
# format for list
add_format_option(parser, "display the list of users in either grid (default)"
", tab, csv, or vertical format - valid only for --list "
"option", "grid")
# Add verbosity and quiet (silent) mode
add_verbosity(parser, True)
# Now we process the rest of the arguments where the first is the
# base user and the next N are the new users.
opt, args = parser.parse_args()
# Fail if dump and quiet set
if opt.quiet and opt.dump:
parser.error("You cannot use --quiet and --dump together.")
# Warn if quiet and verbosity are both specified
check_verbosity(opt)
# Fail if no arguments and no options.
if (len(args) == 0 or opt is None) and not opt.list_users:
parser.error("No arguments found. Use --help for available options.")
# Parse source connection values
try:
source_values = parse_connection(opt.source)
except:
parser.error("Source connection values invalid or cannot be parsed.")
if opt.list_users:
userclone.show_users(source_values, opt.verbosity, opt.format)
else:
# Make sure we have the base user plus at least one new user
if len(args) < 2 and not opt.dump:
parser.error("Wrong parameter combination or no new users.")
base_user = args[0]
new_user_list = args[1:]
# Parse destination connection values if not dumping
if not opt.dump and opt.destination is not None:
try:
dest_values = parse_connection(opt.destination)
except:
parser.error("Destination connection values invalid or cannot "
"be parsed.")
else:
dest_values = None
# Build dictionary of options
options = {
"dump" : opt.dump,
"overwrite" : opt.overwrite,
"quiet" : opt.quiet,
"verbosity" : opt.verbosity,
"global_privs" : opt.global_privs
}
try:
res = userclone.clone_user(source_values, dest_values, base_user,
new_user_list, options)
except UtilError, e:
print "ERROR:", e.errmsg
exit(1)
exit()
|