Skip to content

Instantly share code, notes, and snippets.

@mkeneqa
Last active March 21, 2022 05:30
Show Gist options
  • Save mkeneqa/40f7b67b2fd35fe0a656722010e74a5e to your computer and use it in GitHub Desktop.
Save mkeneqa/40f7b67b2fd35fe0a656722010e74a5e to your computer and use it in GitHub Desktop.
wp back up script
#!/bin/bash
#get the current date
SNAME="$(wp eval 'printf("%s_%d", sanitize_title(site_url()), date("ymdHis"));')"
# set archive backup name and append the date
# eg: https-mywebsite-com_220321051310.zip
SITEBKUPNAME="$SNAME.zip"
# export database
wp db export
# zip up the wp-content dir
zip -r $SITEBKUPNAME wp-content/
# add the exported file to the zip archive
zip -g $SITEBKUPNAME *.sql
# add config file to archive
zip -g $SITEBKUPNAME wp-config.php
# write site url to info file
INFO="$(wp eval 'printf("%s", site_url());')"
echo $INFO > SITE_URL.txt
zip -g $SITEBKUPNAME SITE_URL.txt
# remove the sql and txt files after it is added to archiive
rm *.sql
rm SITE_URL.txt
@szepeviktor
Copy link

SNAME="$(wp eval 'printf("%s-%d", sanitize_title(site_url()), get_current_blog_id());')"

Safe site name.

@mkeneqa
Copy link
Author

mkeneqa commented Mar 10, 2022

@szepeviktor Thanks for that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment