Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogsmv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai
noblogsmv
Commits
d2f39e77
Commit
d2f39e77
authored
9 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
set some useful ssh options
parent
d7bef3b3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
noblogsmv/main.py
+13
-12
13 additions, 12 deletions
noblogsmv/main.py
with
13 additions
and
12 deletions
noblogsmv/main.py
+
13
−
12
View file @
d2f39e77
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment