Created
April 14, 2020 03:44
-
-
Save sudar/f2f6dfc644ea7d2da41e7966622f7df8 to your computer and use it in GitHub Desktop.
Bash script to backup WordPress sites. Add this to a cron job and run it every day
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 | |
NOW=$(date +%Y-%m-%d-%H-%M-%S) | |
SQL_FILE=${NOW}_db.sql | |
# Backup database | |
/usr/local/bin/wp db export ../backups/$SQL_FILE --add-drop-table | |
# Compress the database file | |
gzip ../backups/$SQL_FILE | |
# Backup uploads directory | |
tar -zcf ../backups/${NOW}_uploads.tar.gz wp-content/uploads | |
# Remove backup files that are a month old | |
# If running on OS X, the date command is a bit different: | |
# rm -f ../backups/$(date -v-1m +%Y%m%d*).gz | |
rm -f ../backups/$(date +%Y-%m-%d* --date='1 month ago').gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment