From 1a9a9e6cfa0a7b13e30a3ff51f20013e02aba34c Mon Sep 17 00:00:00 2001 From: Sebastian Berlin Date: Tue, 7 Feb 2023 12:27:11 +0100 Subject: [PATCH] Add Wordpress backup script The script makes a Mysql dump using the variables from the supplied config file. The file is then compressed with Bzip2. --- README.md | 1 + wp-backup.sh | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 wp-backup.sh diff --git a/README.md b/README.md index 20334ba..578448b 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,6 @@ This repository contains miscellaneous scripts used by [Wikimedia Sverige (WMSE) * phabricator-floating-top-bar.user.css - *Stylus CSS for floating top bar in Phabricator.* * google-flip-portrait.user.css - *Stylus CSS for flipping a portrait in google services.* * sites-redirect-test.sh - *Prints the final URL for domains hosted on sites.wikimedia.se to quickly see that redirects work as they should.* +* wp-backup.sh - *Creates a Mysql backup from the config supplied as parameter and compresses it with Bzip2.* When adding a script, also add it to this list with a short description. diff --git a/wp-backup.sh b/wp-backup.sh new file mode 100644 index 0000000..1ec229c --- /dev/null +++ b/wp-backup.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +host=$(sudo php -r "include('$1'); echo DB_HOST;") +db=$(sudo php -r "include('$1'); echo DB_NAME;") +user=$(sudo php -r "include('$1'); echo DB_USER;") +password=$(sudo php -r "include('$1'); echo DB_PASSWORD;") + +mysqldump --add-drop-table -h $host -u $user --password=$password $db | bzip2 -c | pv -p --timer --rate --bytes > backup-$(date --iso-8601).sql.bz2