Skip to content
Snippets Groups Projects
Commit d2f39e77 authored by ale's avatar ale
Browse files

set some useful ssh options

parent d7bef3b3
Branches
No related tags found
No related merge requests found
......@@ -17,14 +17,13 @@ MYSQL_URI_RE = re.compile(
log = logging.getLogger(__name__)
def execute_gen(cmd, dry_run = False):
def execute_gen(cmd, dry_run=False):
if dry_run:
log.info("[DR] %s" % cmd)
return ''
return subprocess.check_output(cmd)
def init(blog_id, value, progress):
return 'move_data'
......@@ -41,7 +40,6 @@ class MysqlNoblogs(object):
self.old = self.conn(old_host,old_port,old_user,old_pass, old_db)
self.new = self.conn(new_host,new_port,new_user,new_pass, new_db)
def options(self, conn):
return '-h%s -P%s -u%s -p%s' % (conn.host,conn.port,
conn.user,conn.password)
......@@ -57,20 +55,19 @@ class MysqlNoblogs(object):
def find_tables(self, blog_id):
find_tables =['mysql', self.options(self.old), self.old.db, '-NBe',
"'show tables like \"wp\\_%s\\_%%\"'" % blog_id]
cmd = ['ssh', 'root@%s' % self.old.host,
"%s" % ' '.join(find_tables)]
cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
'root@%s' % self.old.host, '%s' % ' '.join(find_tables)]
log.debug('Calling %s', ' '.join(cmd))
raw_tables = subprocess.check_output(cmd)
self.tables = [ t.strip() for t in raw_tables.splitlines()]
def process_move_data(blog_id, value, progress):
progress.update('moving blog data')
log.info('moving data for %s', blog_id)
blog_dir = os.path.join(BLOGS_DIR, blog_id)
cmd = ['ssh', 'root@%s' % value['old_host'], 'rsync', '-az',
cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
'root@%s' % value['old_host'], 'rsync', '-az',
'%s/' % blog_dir, 'root@%s:%s' % (value['new_host'], blog_dir)]
log.debug('Calling %s', ' '.join(cmd))
try:
......@@ -106,7 +103,8 @@ def process_move_db(blog_id, value, progress):
tables = ' '.join(db.tables)
move_db = ['mysqldump', '--opt', db.old_options, value['old_db'], tables,
'|', 'mysql', db.new_options, value['new_db']]
cmd = ['ssh', 'root@%s' % value['old_host'], '%s' % ' '.join(move_db)]
cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
'root@%s' % value['old_host'], '%s' % ' '.join(move_db)]
log.debug('Calling %s', ' '.join(cmd))
try:
execute(cmd)
......@@ -137,7 +135,8 @@ def process_rm_db(blog_id, value, progress):
tables = ', '.join(db.tables)
drop_db = ['mysql', db.old_options, db.old.db, '-NBe',
'"DROP TABLE %s"' % tables]
cmd = ['ssh', 'root@%s' % value['old_host'], '%s' % ' '.join(drop_db)]
cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
'root@%s' % value['old_host'], '%s' % ' '.join(drop_db)]
try:
execute(cmd)
except (subprocess.CalledProcessError, OSError), e:
......@@ -147,11 +146,13 @@ def process_rm_db(blog_id, value, progress):
progress.update('removed blog db; Done.')
return state.STATE_DONE
def process_rm_data(blog_id, value, progress):
progress.update('removing blog data files from old location')
log.info('Removing blog data files')
blog_dir = os.path.join(BLOGS_DIR, blog_id)
cmd = ['ssh', 'root@%s' % value['old_host'], 'rm', '-rf',
cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
'root@%s' % value['old_host'], 'rm', '-rf',
'%s/' % blog_dir]
log.debug('Calling %s', ' '.join(cmd))
try:
......@@ -231,7 +232,7 @@ use the `--recover' option.
level=(logging.DEBUG if opts.debug else logging.INFO))
global execute
execute = partial(execute_gen, dry_run = opts.dry_run)
execute = partial(execute_gen, dry_run=opts.dry_run)
if opts.clean:
statemachine = NoblogsCleanStateMachine
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment