# How to keep 2 Wordpress sites synced



## balanga (Jan 24, 2018)

I want to be able to keep an Internet Wordpress site synced up with a local site.

Is anyone aware of any guides on how to do this?

Both sites will be running on FreeBSD.


----------



## obsigna (Jan 25, 2018)

I maintain a synched copy of my BLog on my web development machine -- like I do with other web applications as well. Usually I set up the database backend of a web application to be a slave which would be replicated automatically by the master once there are any changes. Unfortunately master/slave replication does not work as intended with WP sites, because the internal links of a WP site are stored by their full URL into the database, and therefore a straight copy of a WP database would work only on a WP site which got exactly the same URL.

My solution is that I run a mysqldump(1) on the master site from a cron job which I fetch by scp(1) to my local development machine when needed -- I could do this with a cron job as well.

`mysqldump --user=root --password=uLtRaSeCrEt12345 --default-character-set=utf8 --tz-utc --set-gtid-purged=OFF wpdbname > wpdbname.sql`

Since the MySQL dump is simply a text file of MySQL commands and the contents are in plain text, I utilize sed(1) to substitute in the SQL dump the URL of the master site - in my case https://obsigna.net - by the URL of the local site - in my case https://localhost/blog.obsigna.net. I wrote a shell script for doing this:

```
#!/bin/sh
/usr/bin/sed -e "s/https:\/\/obsigna.net/https:\/\/localhost\/blog.obsigna.net/g" -i "" /path/to/wpdbname.sql
/usr/bin/sed -e "s/%2Fobsigna.net/%2Flocalhost%2Fblog.obsigna.net/g" -i "" /path/to/wpdbname.sql
echo "drop database wpdbname; create database wpdbname;" | mysql --user=root --password=uLtRaSeCrEt12345 --default-character-set=utf8
mysql --user=root --password=uLtRaSeCrEt12345 --default-character-set=utf8 wpdbname < /path/to/wpdbname.sql
```

Of course you would need to adapt the script for your URL's respectively.
Of course you would need to set up a working WP installation on your local machine.
Image and media data you would need to transfer using e.g. scp(1) as well.


----------



## PacketMan (Jan 25, 2018)

Could net-p2p/btsync work for you?  I have done some neat things with it, and for the most part it works really well. Sometimes syncing seems to get stuck, but that maybe also be caused by me messing around.


----------



## azathoth (Jan 26, 2018)

balanga said:


> I want to be able to keep an Internet Wordpress site synced up with a local site.
> 
> Is anyone aware of any guides on how to do this?
> 
> Both sites will be running on FreeBSD.


Cname site 1 to site 2, make sure all users same.


----------



## balanga (Jan 26, 2018)

azathoth said:


> Cname site 1 to site 2, make sure all users same.



Thanks for the advice, but I don't understand what you mean.


----------



## azathoth (Jan 26, 2018)

balanga said:


> Thanks for the advice, but I don't understand what you mean.


Have 1 wordpress and point both DNS names to it.
Problem solved!
A cname is a DNS record that point fo example site44.com to yoursite.com.

sorcery!
occamz razor n all that


----------

