Initial import.

This commit is contained in:
flash 2023-09-05 14:31:41 +00:00
commit 8a74f4162f
6 changed files with 75 additions and 0 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
[Tt]humbs.db
[Dd]esktop.ini
.DS_Store
.vscode/
.vs/
.idea/
/config.sh

12
LICENCE Normal file
View file

@ -0,0 +1,12 @@
Copyright (c) 2023, flashwave <me@flash.moe>
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.

5
README.md Normal file
View file

@ -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.

9
config.sh.example Executable file
View file

@ -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"

41
db-backup.sh Executable file
View file

@ -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"