commit 8a74f4162febd9caaf94473fd8c1348fec98d897 Author: flashwave Date: Tue Sep 5 14:31:41 2023 +0000 Initial import. diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d82ad0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +[Tt]humbs.db +[Dd]esktop.ini +.DS_Store +.vscode/ +.vs/ +.idea/ +/config.sh diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..a668262 --- /dev/null +++ b/LICENCE @@ -0,0 +1,12 @@ +Copyright (c) 2023, flashwave + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc3ef4f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Backup Tools + +This repository is the replacement for the old C# Backup Manager program. + +After reducing the amount of things the backup program was doing, I realised it made much more sense to just use Bash scripts to achieve the same thing, so here we are. diff --git a/config.sh.example b/config.sh.example new file mode 100755 index 0000000..202cc45 --- /dev/null +++ b/config.sh.example @@ -0,0 +1,9 @@ +#!/bin/sh + +# Credentials for a MariaDB user with the following grant: +# GRANT SELECT, LOCK TABLES, SHOW VIEW, SHOW DATABASES, EVENT, TRIGGER, EXECUTE ON *.* TO 'user'@'localhost'; +mariadb_user="username" +mariadb_pass="password" + +# Path to where to storage the finished archives. Obviously you should move these to a more permanent location afterwards. +db_backups_depot="/path/to/backup/storage" diff --git a/db-backup.sh b/db-backup.sh new file mode 100755 index 0000000..2caee45 --- /dev/null +++ b/db-backup.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +filename="$(hostname) $(date +'%Y-%m-%d %H%M%S')" +skip_dbs=("mysql" "information_schema" "performance_schema" "sys") +tmpdir="/tmp/fw-db-backup" +workdir="$tmpdir/$filename" +mariadb_user="" +mariadb_pass="" +db_backups_depot="." + +if [ ! -e config.sh ]; then + echo "config.sh not found, copy config.sh.example if you haven't yet" + exit 1 +fi + +source ./config.sh + +echo "Resetting temp directory..." +rm -rf "$tmpdir" +mkdir -p "$workdir" + +dbs=$(mysql -u "$mariadb_user" -p"$mariadb_pass" --skip-column-names -e "SHOW DATABASES") + +for db in $dbs; do + if [[ " ${skip_dbs[@]} " =~ " $db " ]]; then + continue + fi + + echo "Dumping $db.sql..." + mysqldump --default-character-set=utf8mb4 --single-transaction \ + --tz-utc --triggers --routines --hex-blob --add-locks \ + --order-by-primary --skip-lock-tables -QqB \ + -u "$mariadb_user" -p"$mariadb_pass" \ + --result-file="$workdir/$db.sql" $db +done; + +echo "Creating package..." +tar -cjvf "$db_backups_depot/$filename.tar.bz2" -C "$tmpdir/" "$filename" + +echo "Cleaning up..." +rm -r "$tmpdir"