A handy collection of shell scripts for working with WordPress installs (initially built for MediaTemple sites).
sitecopy.sh - Copies a wordpress site from one domain to another. Uses wpdbclear.sh, wpdbdump.sh, and Search Replace DB.
Usage:
sitecopy.sh [options] old_domain new_domain
Options:
-h Show this message
--artifactdir=PATH Place to put backups and migration artifacts. Defaults to working directory.
--oldsitedir=PATH Server address. Defaults to '~/domains/OLD_DOMAIN/html'
--newsitedir=PATH Server root password. Defaults to '~/domains/NEW_DOMAIN/html'
What sitecopy.sh
does:
- Creates a directory for artifacts (uses the current timestamp - YYYYmmddHHMMSS)
- Backs up up the site to overwrite into the artifacts directory (new_domain)
tar
s the web root directory- Dumps the database using
wpdbdump.sh
- Adds the database dump to the site tar file
gzip
s the tar file- Deletes the database dump
- Backs up the domain to copy (old_domain)
- Prepares copy of old_domain's database for new_domain
- Dumps old_domain's database using
wpdbdump.sh
- Creates a copy of the old_domain db backup to be modified for new_domain
- Switches table prefixes in copy to match new_domain's
wp-config.php
prefix - Preserves new_domain's
wp-config.php
file for swapping into old_domain's source directory - Replaces new_domain's source code with old_domain's
- Nukes new_domain's source code
- Extracts old_domain's tar into new_domain's place
- Nukes any updraft backups or logs in new_domain
- Replaces all mentions of old_domain in new_domain's source code with new_domain
- Overwrites new_domain
wp-config.php
file with preserved version - Runs
wpclear.sh
to replace new_domain's database with old_domain copy - Drops new_domain's database and re-creates it
- Imports copy of old_domain's database
- Runs Search Replace DB to replace all instances of old_domain with new_domain
- wpdbclear.sh - Replaces a database with a dump file using the credentials in a wp-config.php file.
- wpdbdump.sh - Dumps a wordpress database using the credentials in a wp-config.php file.
- wpdbgetcred.sh - Gets a specified database credential from a wp-config.php file.
- wpdblogin.sh - Logs into a mysql prompt using the database credentials in a speficied wp-config.php file.