Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 45 lines (37 sloc) 1.36 KB
set -e -f -u -o pipefail
wp_option() {
local option="$1" config="$2"
readonly option config
awk -F \' "/${option}/"' { print $4 }' "${config}"
main() {
local config="$1/wp-config.php" db_password db_name db_user date
readonly config
db_password="$(wp_option DB_PASSWORD "${config}")"
db_name="$(wp_option DB_NAME "${config}")"
db_user="$(wp_option DB_USER "${config}")"
date="$(date +%Y-%m-%d-%H-%M)"
readonly db_password db_name db_user date
for command in --check --analyze; do
mysqlcheck "${command}" --auto-repair --silent \
--user="${db_user}" --password="${db_password}" --databases "${db_name}"
local dest="${HOME}/wordpress-backups"
if [ ! -d "${dest}" ]; then
mkdir -p "${dest}"
chmod 0700 "${dest}"
cd "${dest}"
# --skip-extended-insert makes the dump more readable because it uses
# individual insert statements rather than one giant insert statement.
# Do not use --databases flag because it adds "use $database" and "create
# database $database" lines, which cause problems for restore-dev-from-www.
mysqldump --add-drop-table --host=localhost \
--user="${db_user}" --password="${db_password}" \
"${db_name}" \
| bzip2 -c > "${db_name}_${date}".sql.bz2
flock "${HOME}/tmp/locks/backup-wordpress__tmpreaper" tmpreaper --mtime 90d .
main "$1"