From bc42fa716a0cff7897973951154af46f7e9df307 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Wed, 27 Jan 2016 04:51:55 -0500 Subject: [PATCH] Basic MySQL database backup --- WPS-Backup.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 WPS-Backup.sh diff --git a/WPS-Backup.sh b/WPS-Backup.sh new file mode 100644 index 0000000..ec22621 --- /dev/null +++ b/WPS-Backup.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# DebianWPS. Debian WordPress-Scripts to manage WordPress installations. +# Copyright (C) 2016 Kris Lamoureux + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# Take input and double check. +takeinput () +{ + while true; do + read -p $1 answer + read -p "Is \"$answer\" your final answer? (Y/n)" yn + + if [ "$yn" == "Y" ]; then + echo $answer + break + fi + + done +} + +# Get input on MySQL database +echo "Attempting to backup MySQL database..." +echo "Please enter MySQL information below:" +user=$(takeinput "Username:") +pass=$(takeinput "Password:") +host=$(takeinput "Host:") +db=$(takeinput "Database:") + +# Get current time in seconds. +time=$(date +%s) + +# Backup a MySQL database +mysqldump --user=$user --password=$pass --host=$host $db > $db-$time.sql + +echo "MySQL database $db has been backed up." +