Skip to content

Instantly share code, notes, and snippets.

@fumikito
Created February 2, 2018 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumikito/2a2c7bbaa103e83ef7965b507ab748b5 to your computer and use it in GitHub Desktop.
Save fumikito/2a2c7bbaa103e83ef7965b507ab748b5 to your computer and use it in GitHub Desktop.
Backup statics of WordPress
#
# Backup WordPress contents.
#
set -e
# Move to WordPress dir
cd /var/www/wordpress
# Remove if exists.
if [ -f wp-content/backup.tar.gz ]; then
rm wp-content/backup.tar.gz
fi
if [ -d wp-content/backup.folder ]; then
rm -rf wp-content/backup.folder
fi
# Make directory
mkdir -p wp-content/backup.folder/
# Backup database.
/usr/local/bin/wp db export wp-content/backup.folder/wordpress_db.sql --add-drop-table
# Copy upload folder
cp -r wp-content/uploads wp-content/backup.folder/uploads
echo "Uploaded files copied"
# Copy plugin folder
cp -r wp-content/plugins wp-content/backup.folder/plugins
echo "Plugins copied"
# Zip archive
cd wp-content
tar czf backup.tar.gz backup.folder
echo "Zip Created."
# remove directory
rm -rf backup.folder
echo "Done.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment