From 85ad3aba48c8a76a3f51427d480039017ad1c4c0 Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Wed, 11 Jun 2025 19:04:36 +0200 Subject: [PATCH] V0.1.1 - templates.fix/scripts: new: BtrSnapshot, SvWebapp - templates.local/scripts: new: SvWebapp.conf - webapps.yaml: Korrektur der Syntax --- CHANGELOG.md | 7 ++- templates.fix/scripts/BtrSnapshot | 69 +++++++++++++++++++++++++++ templates.fix/scripts/SvWebapp | 26 ++++++++++ templates.local/scripts/SvWebapp.conf | 3 ++ templates.vars/webapps.yaml | 3 +- 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 templates.fix/scripts/BtrSnapshot create mode 100644 templates.fix/scripts/SvWebapp create mode 100644 templates.local/scripts/SvWebapp.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index 51ee0d2..3f31eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,6 @@ -# Change log of +# V0.1.1 + +- templates.fix/scripts: new: BtrSnapshot, SvWebapp +- templates.local/scripts: new: SvWebapp.conf +- webapps.yaml: Korrektur der Syntax + diff --git a/templates.fix/scripts/BtrSnapshot b/templates.fix/scripts/BtrSnapshot new file mode 100644 index 0000000..9c53daa --- /dev/null +++ b/templates.fix/scripts/BtrSnapshot @@ -0,0 +1,69 @@ +#! /bin/bash +# BtrSnapshot [-q] MODE FILESYSTEM SRC [LOG] +# BtrSnapshot daily /media/fs.cave mirror.home /tmp/snap.log +VERBOSE=-v +LOG=/var/log/local/btrsnapshot.log +if [ "$1" = -q ]; then + VERBOSE= + shift +fi +MODE=$1 +FILESYSTEM=$2 +SRC=$3 +test -n "$4" && LOG="$4" +export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin + +function Usage(){ + echo "Usage: BtrSnapshot MODE FILESYSTEM SOURCE [LOGFILE]" + echo "Example: BtrSnapshot daily /media/fs.cave home" + echo "Example: BtrSnapshot daily /media/fs.cave opt /var/log/mylog.log" + echo "+++ $*" +} +function Log(){ + test -n "$VERBOSE" && echo "$*" + date "+%Y.%m.%d-%H:%M:%S $*" >>$LOG +} +function MakeSnapshot () { + local mode=$1 + local filesys=$2 + local src=$3 + local subdir + case $mode in + daily) + subdir=$(LANG=C date +%a) + ;; + weekly) + subdir=$(date +%W) + subdir=$(expr $subdir "%" 4) + ;; + monthly) + subdir=$(date +%m) + ;; + temp) + subdir=temp + ;; + esac + local trg=$filesys/snapshots/$src/$mode + if [ ! -d $trg ]; then + Log "creating $trg..." + mkdir -p $trg + fi + trg="$trg/$subdir" + if [ -d $trg ]; then + Log "$(btrfs subvol delete $trg)" + fi + Log "$(btrfs subvol snapshot -r $filesys/$src $trg)" +} +if [ "$MODE" = "auto" ]; then + MODE=daily + test "$(date +%w) = 6 && MODE=weekly + test "$(date +%d) = 01 && MODE=monthly +fi + +if [ -z "$SRC" ]; then + Usage "too few arguments" +elif [ ! -d $FILESYSTEM/$SRC ]; then + Usage "missing $FILESYSTEM/$SRC" +else + MakeSnapshot $MODE $FILESYSTEM $SRC +fi diff --git a/templates.fix/scripts/SvWebapp b/templates.fix/scripts/SvWebapp new file mode 100644 index 0000000..fd48e8c --- /dev/null +++ b/templates.fix/scripts/SvWebapp @@ -0,0 +1,26 @@ +#! /bin/bash +VERBOSE=-v +if [ "$1" == '-q' ]; then + VERBOSE= + shift +fi +DOMAIN=$1 +DB=$2 +PATH=/usr/bin:/bin +. /usr/local/bin/local/SvWebapp.conf +DATE=$(date "+%Y.%m.%d_%H_%M") +BASE=$DIR_WWW/$DOMAIN +TAR=$DIR_ARCHIVE/$DOMAIN.$DATE.tgz +if [ -z "$DB" ]; then + echo "Usage: SvWebapp DOMAIN DB" + echo "Example SvWebapp stage.infeos.net swstageinfeos" + echo "+++ missing DOMAIN" +elif [ ! -d $BASE ]; then + echo "+++ missing $BASE" +else + cd $BASE/db + mysqldump $DB | gzip >$DOMAIN.sql.gz + cd $BASE + tar czf $TAR . + test -n "$VERBOSE" && ls -l $TAR +fi diff --git a/templates.local/scripts/SvWebapp.conf b/templates.local/scripts/SvWebapp.conf new file mode 100644 index 0000000..2ca8b6b --- /dev/null +++ b/templates.local/scripts/SvWebapp.conf @@ -0,0 +1,3 @@ +DIR_WWW=/srv/www +DIR_ARCHIVE=/media/backup/archive + diff --git a/templates.vars/webapps.yaml b/templates.vars/webapps.yaml index c8656c3..136368e 100644 --- a/templates.vars/webapps.yaml +++ b/templates.vars/webapps.yaml @@ -1,8 +1,9 @@ --- # Configuration data of the web applications webapps_list: - - dummy + - webapp_name: dummy.example.com db_name: dbdummy5 + db_type: mysql db_user: dummy5 db_password: NeverKnown5 directory: /srv/www/myapp5.example.com -- 2.39.5