WebFaction
Community site: login faq

Has anyone created a script that does anything close to the following? (I am going to try to write something like this)

It would be a script to migrate a CMS based website from remote host to WF

Take the following information from the user:

  • remote host shell user account name and password
  • directory path on remote host
  • remote host database password and username
  • domain name

With that info, it would do the following:

  • Create the application, website, domain, and db in WF through the WF api
  • use ssh to remotely log into the other host and run a mysqldump command, piping the output to a mysql command on WF that will create the CMS (wordpress) tables here.
  • rsync the remote files over to WF

asked 30 Aug '14, 15:31

wesyah234
4326
accept rate: 50%


This is what I came up with a while back (late 2014) but never finished... it was close... basically I was using the WF api to create the appropriate domain, website, app, etc.. then putting together an ssh command that would ssh into my other machine and execute the commands to do a mysql dump, and then pipe that result into a mysql command locally at WF that would import the database schema into the newly created database.

It was tricky as you can see by the comments, because WF creates a default user but I don't want that, I want my own user to match the username from the other machine (ie so I wouldn't need to change the wordpress config files to use a different username)

as I remember, it basically worked... But the next step would be to do an rsync to pull over the actual php files....if anyone wants to improve upon it, go ahead!

import xmlrpclib

remoteHost = "0.0.0.0"
remoteUser = "username"

remoteDbName = "wordpress_dbname"
remoteDbPass = "pass"
remoteDbUser = "wordpress_dbuser'"

wfDbName = remoteDbName
wfDbPass = remoteDbPass
wfDbUser = remoteDbUser
wfDbType = "mysql"

domainName = "domain.com"
domainNameNoDot = "domain"
domainNameWWW = "www.domain.com"

server = xmlrpclib.ServerProxy("https://api.webfaction.com/")
session_id, account= server.login("wfusername", "wfpassword")
server.create_app(session_id, domainNameNoDot, "static", False, "", False)
server.create_domain(session_id, domainName, "www")
server.create_website(session_id,domainNameNoDot,"wfipaddresshere",False,[domainName, domainNameWWW])

#create the wf db, with a dummy password for the default user that will get created automatically
server.create_db(session_id, wfDbName, wfDbType, 'dontusepassword')
#then, delete that user created automatically with the same name as the db
server.delete_db_user(session_id, wfDbName, wfDbType)
#then create the user we really want
server.create_db_user(session_id, wfDbUser, wfDbPass, wfDbType)
#and give that user perms to the database
server.grant_db_permissions(session_id, wfDbUser, wfDbName, wfDbType)

cmd = "ssh " + remoteUser + "@" + remoteHost +  " 'mysqldump --user=" + remoteDbUser + " -p\"" + remoteDbPass + "\""  + " --add-drop-table --no-create-db --skip-lock-tables " + remoteDbName + "'" + " | mysql --user=" + wfDbUser + " -p\"" + wfDbPass + "\" " + wfDbName

print cmd

# eventually, when this works properly, we will execute the above command.
permanent link

answered 29 Feb '16, 03:21

wesyah234
4326
accept rate: 50%

You should upload this to a repository hosting service like GitHub or Bitbucket :)

(29 Feb '16, 11:06) iliasr ♦♦

Here it is... if anyone wants to complete it go right ahead!... I don't really need to do this anymore but maybe someone can benefit from the work so far.

https://github.com/wesyah234/webfaction-migrate

(04 Mar '16, 23:07) wesyah234

I am not aware of a script. however it is very similiar to Moving a WordPress Site that we have in our Documentation. You certainly want to keep in mind the changes to the database structure that we mention.

Good luck with the script and we would appreciate you sharing the results with our community.

permanent link

answered 30 Aug '14, 15:37

aaront ♦♦
7664
accept rate: 27%

What do you mean by "changes to the database structure"?

(30 Aug '14, 15:48) wesyah234

The important things would be the database name, username, and the host name as they will almost always be changed. from another provider. I am sure you had those covered already, but wanted to make sure to remind people.

(30 Aug '14, 15:52) aaront ♦♦

Noted. I see there's a replace_in_file api method that will come in handy to specify the new connection params if different...

(30 Aug '14, 23:15) wesyah234
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×244
×75
×44

question asked: 30 Aug '14, 15:31

question was seen: 2,644 times

last updated: 04 Mar '16, 23:08

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM