jplew / SyncDB

Bash script meant to take the tedium out of deploying and updating database-driven (eg Wordpress) websites. It rapidly synchronizes local and remote versions of a MySQL database, performs the necessary search and replace queries, then synchronizes all your uploads/binaries.
MIT License
234 stars 41 forks source link

Syntax error on replace_remote_db #8

Closed marcobarbosa closed 9 years ago

marcobarbosa commented 10 years ago

Hi,

First of all thanks for this excellent script! I'm really impressed. I'm running into trouble with a hosting that doesn't give me "DROP" privileges. So I've added here: no_drop=true # set to true if your host sucks

...because my host sucks :D

Then I get this:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>/dev/null 2>&1' at line 1

Which is related to this:

sql_show="show databases; create database if not exists $r_db_name >/dev/null 2>&1;"

        echo "mysql -u$r_db_user -p$r_db_pass -h $r_db_host --show-warnings -Bse $sql_show"

        mysql -u$r_db_user -p$r_db_pass -h $r_db_host --show-warnings -Bse "$sql_show"

Any ideas on where this syntax error is? Ill keep looking.

jplew commented 10 years ago

Hi Marco: thanks for submitting the bug. Out of curiosity, which version of bash is your server using? To find out type this: bash --version

Not sure why it's giving that error, all we are doing is suppressing output by redirecting it to /dev/null—it's quite standard.

Do you mind running a test for me? Change that line by removing the offensive syntax, like this: sql_show="show databases; create database if not exists $r_db_name;"

Is it still giving the same error? Thank. -JP

jplew commented 10 years ago

I just pushed an updated, I noticed there was an unrelated error in the script which would have prevented it from working anyway. Before you test again can you download the new version of syncdb? Thanks.

marcobarbosa commented 10 years ago

Thanks jplew! I just tested it again.

After the show databases; create database if not exists $r_db_name it feels like i have to hit enter in the console to get going, then right after I get:

./syncdb: line 957: $1: unbound variable

I get no errors after this notice but the database is not pushed (as the old one remains).

jplew commented 10 years ago

There was a problem with the variable substitution, thanks again for bringing this to my attention.

I have attempted to fix this bug in the latest version. When you get the chance, please download the newest version and try again. It's not required but you may want to update your syncdb-config too (I just added a new parameter at the bottom, which enables auto-updating). Thanks!

marcobarbosa commented 10 years ago

Ok, I tried again and this time I got:

Enter password: Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

It's weird because I didn't get this error before..

Unrelated question: Is there a reason why you don't download the plugins folder in the rsync_pull and rsync_push? I would be willing to give you a pull request with that suggestion (should be really easy to duplicate what you have for uploads) if you find it interesting.

jplew commented 10 years ago

Regarding that error, can you please do me a favor and send me the error log? Try executing the script again like this: bash -x ./syncdb then post the gist (https://gist.github.com/).

Secondly, I personally prefer not to sync the plugins folder via rsync, because I prefer to keep all the plugins and themes in version control and synced via git. Plugins and themes work hand in hand, and are code, so they lend themselves better to git. Uploads (media) on the other hand don't lend themselves to version control as well, because git isn't made for binaries.

Of course, if you prefer not to go that route, then rsync can handle plugins no problem. What I would do is change the "uploads" folder to wp-content/, then exclude the themes folder, and and anything else you don't want rsync'ed. Hope that makes sense. Please let me know.

marcobarbosa commented 9 years ago

Hey @jplew

I've just tested the script again and it works like a charm. Using a different hosting though.