Last active
August 29, 2015 14:07
-
-
Save mariuswilms/21c874c8a8e1785fb17e to your computer and use it in GitHub Desktop.
Migration scripts to change URLs in blog posts from lithify.me to li3.me
This file contains 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
#!/bin/bash | |
# Fill in your connection details. | |
DATABASE="blog" | |
COLLECTION="posts" | |
USER="" | |
PASS="" | |
# | |
AUTH="" | |
if [[ $USER != "" ]]; then | |
AUTH+="-u $USER" | |
fi | |
if [[ $PASS != "" ]]; then | |
AUTH+="-p $PASS" | |
fi | |
# Recommended: Optionally uncomment to create a backup before we're applying changes. | |
# mongodump -d $DATABASE -c $COLLECTION $AUTH | |
SCRIPT=" | |
var cursor = db.${COLLECTION}.find(); | |
while (cursor.hasNext()) { | |
var item = cursor.next(); | |
print('Before.. ' + item.body); | |
item.body = item.body.replace(/lithify.me/g, 'li3.me'); | |
print('After... ' + item.body); | |
db.${COLLECTION}.update({_id : item._id}, item); | |
} | |
" | |
echo $SCRIPT > script.js | |
mongo $DATABASE $AUTH ./script.js | |
# Cleanup | |
rm script.js |
This file contains 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
#!/bin/bash | |
# Fill in your connection details. | |
DATABASE="blog" | |
USER="root" | |
PASS="" | |
# | |
AUTH="" | |
if [[ $USER != "" ]]; then | |
AUTH+="-u $USER" | |
fi | |
if [[ $PASS != "" ]]; then | |
AUTH+="-p$PASS" | |
fi | |
# Recommended: Optionally uncomment to create a backup before we're applying changes. | |
# mysqldump --opt $AUTH $DATABASE > backup.sql | |
SCRIPT=" | |
UPDATE wp_posts SET post_content = REPLACE ( post_content, 'lithify.me', 'li3.me'); | |
" | |
echo $SCRIPT | mysql $AUTH $DATABASE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment