Last active
March 21, 2022 05:30
-
-
Save mkeneqa/40f7b67b2fd35fe0a656722010e74a5e to your computer and use it in GitHub Desktop.
wp back up script
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 | |
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SNAME="$(wp eval 'printf("%s-%d", sanitize_title(site_url()), get_current_blog_id());')"
Safe site name.