Skip to content

Instantly share code, notes, and snippets.

@thursby
Last active August 28, 2016 17:08
Show Gist options
  • Save thursby/7395ce457ae6b1fbe49fee6d1e41cd20 to your computer and use it in GitHub Desktop.
Save thursby/7395ce457ae6b1fbe49fee6d1e41cd20 to your computer and use it in GitHub Desktop.
Back up the bare minimum from a WordPress installation -- useful when WordPress has been compromised
#!/bin/bash
# This uses the system's tmp directory, set a custom one with --tmpdir=/where/ever
tmp_dir=`mktemp -d`
echo Work Directory: $tmp_dir
files_to_keep=("wp-config.php" "wp-content/uploads")
for i in ${files_to_keep[@]}; do
echo "Copying ${i}"
cp -R ${i} $tmp_dir # Replace with mv for speed once it's working right
done
echo "Backing up WordPress Database and saving data"
wp db export $tmp_dir/database.sql
wp core version > $tmp_dir/wp_version.txt
wp plugin list --format=csv > $tmp_dir/wp_plugins.txt
wp theme list --format=csv > $tmp_dir/wp_themes.txt
do_not_compress=".tiff:.gif:.snd:.png:.jpg:.jpeg:.mp3:.tif"
zip --suffixes $do_not_compress -1 -r $tmp_dir/backup.zip -x@"exclude.txt" .
echo "Finished backing up to: $tmp_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment