Forked from chuckreynolds/wordpress-change-domain-migration.sql
Created
August 14, 2019 10:40
-
-
Save vunb/3137113f0b749c6c30fcd17f738292f7 to your computer and use it in GitHub Desktop.
Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work. __STEP1: always backup your database. __STEP2: change the ‘oldsite.com’ and ‘newsite.com’ variables to your own. __STEP3: make sure your databa…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @oldsite='http://oldsite.com'; | |
SET @newsite='http://newsite.com'; | |
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl'; | |
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite); | |
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite); | |
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite); | |
/* only uncomment next line if you want all your current posts to post to RSS again as new */ | |
#UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite); |
I made a web page that shows this better.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the help of your code I got a backup of my WordPress on another WordPress and with the help of ChatGPT made this text up to make scripts to copy all the database and media to a backup of WordPress. Here is what came up with:
A script to copy WordPress to a backup WordPress from rday1 to server. Replace them name in here with what your WordPress domin name.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
ssh-keygen -t rsa -b 4096
ssh-copy-id root@rday1
nano /root/.my.cnf
[client]
user=root
password=your_password
chmod 600 /root/.my.cnf
On rday1
nano Script on rday1: WP-copy-DB_to_server.sh
#!/bin/bash
wp db export --allow-root --path=/var/www/html backup.sql
scp "/root/backup.sql" root@server:/root/backup.sql
back on other WordPress
nano Get-WP-DB-from_rday1.sh
#!/bin/bash
wp db import /root/backup.sql --allow-root --path=/var/www/html
mysql wordpressdb < /root/wordpress-change-domain-migration.sql
rsync -avP --delete root@rday1:/var/www/html/wp-content/uploads/ /var/www/html/wp-content/uploads
chmod 700 Get-WP-DB-from_rday1.sh
nano wordpress-change-domain-migration.sql
SET @oldsite='https://rday.me/blog';
SET @newsite='http://server';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
#UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite)
on rday1 again.
crontab -e
0 2 * * * /root/WP-copy-DB_to_server.sh
Then back on server
crontab -e
20 2 * * * /root/Get-WP-DB-from_rday1.sh
On rday1 again
ssh-copy-id
ssh-copy-id root@server
That it's.
Cane test by running this on rday1
sh WP-copy-DB_to_hp2.sh
Then on server
sh Get-WP-DB-from_rday1.sh
I any one does this post back let me know if it works.
You can easy install WordPress from a script here:
https://linux.how2shout.com/script-to-install-lamp-wordpress-on-ubuntu-20-04-lts-server-quickly-with-one-command/