Last active
August 3, 2017 11:21
-
-
Save lrkwz/7237c49b3ee4bf4f19801f24034c8593 to your computer and use it in GitHub Desktop.
Estract a tar of images used by wordpress
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 | |
set -e | |
if [ "$1" != "" ]; then | |
FNAME=$(mktemp /tmp/foo.XXXXXXXXX) | |
cat <<EOSQL | mysql -u root -p $1 | sed -e s/\.[^\.]*$/\*/ | sed -e "s/^/ls /" > $FNAME | |
SELECT distinct files.meta_value AS '' | |
FROM | |
wp_posts posts | |
INNER JOIN wp_posts attachments ON posts.ID = attachments.post_parent | |
INNER JOIN wp_postmeta files ON attachments.ID = files.post_id | |
WHERE files.meta_key = '_wp_attached_file' | |
UNION | |
SELECT distinct REGEXP_REPLACE( guid, '^htt.*\/uploads\/','') | |
FROM wp_posts attachments | |
INNER JOIN wp_postmeta files ON attachments.ID = files.post_id | |
WHERE post_mime_type LIKE 'image%'; | |
EOSQL | |
CURDIR=$(basename `pwd`) | |
if [ "$CURDIR" == "uploads" ];then | |
TARLIST=$(mktemp /tmp/tar.XXXXXXXXX) | |
sh $FNAME > $TARLIST | |
tar -c -f /tmp/$1.tar -T $TARLIST | |
echo "Trovi le immagini di $1 in /tmp/$1.tar" | |
else | |
echo "cd to $1/wp-content/uploads dir first" | |
fi | |
else | |
echo "$0 dbname" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be useful to extract a tar of used images in a given wordpress site.