diff --git a/beispiele/17/borg-www-backup.rb b/beispiele/17/borg-www-backup.rb deleted file mode 100644 index 5ad992f..0000000 --- a/beispiele/17/borg-www-backup.rb +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env ruby -require "date" -require "fileutils" - -$NOW = Date.today.strftime("%d-%m-%Y_%H:%M:%S") - -# borg repository -$REPO = "/home/dany/backups/borg" - -# websites folder -$WEBSITESDIR = "/home/dany/www" - -# local backup folder for db files -$BACKUPDIR = "/home/dany/backups" - -unless File.exist?( $BACKUPDIR ) - FileUtils.mkdir_p( $BACKUPDIR ) -end - - -# Unterverzeichnisse von www die gebackuppt werden sollen -liste = [ - "conf", - "danletard.de", - "papier-restaurierung", - "schubertdaniel", - "x2ero", - "conworx", - "rvv/wp-content", - "rvv/shop" - ] - - -# websites -def websites( liste ) - Dir.chdir( $WEBSITESDIR ) - - liste.each do |elem| - if File.exist?( elem ) - `borg create -C zlib,8 #{$REPO}::#{elem}-{now:%d-%m-%Y_%H:%M:%S} #{elem} --exclude '*mpeg'` - - else - puts "File or Directory \"#{elem}\" not found!\n" - end - end - -end - -# davical db backup -def calendar_db_backup - Dir.chdir( $BACKUPDIR ) - `pg_dump -U davical_app davical | gzip > kalender-#{$NOW}.psql.gz` -end - -# wordpress db backup -def wp_db_backup - host= "localhost" - user= "rvv" - pass= "owUy9JTWLHQ0" - #db= "rvv0rettung" - db= "rvv_dev" - - do_sql_backup(host,user,pass,db) -end - -# oxid db backup -def oxid_db_backup - host= "localhost" - user= "rvv" - pass= "owUy9JTWLHQ0" - db= "rvv_shop" - - do_sql_backup(host,user,pass,db) -end - -# -# Helper function -# -def do_sql_backup(host,user,pass,db) - Dir.chdir( $BACKUPDIR ) - `mysqldump --opt --add-drop-table -h#{host} -u#{user} -p#{pass} #{db} | gzip > #{db}-#{$NOW}.sql.gz` -end - -websites( liste ) -wp_db_backup -oxid_db_backup -calendar_db_backup - -FileUtils.chown_R( 1000, 1000, $BACKUPDIR) - - diff --git a/beispiele/17/wp-backup.sh b/beispiele/17/wp-backup.sh deleted file mode 100644 index 2d83b2a..0000000 --- a/beispiele/17/wp-backup.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -function db_backup { - - # Vars - host=localhost - user=XXXXXXX - pass=XXXXXXX - db=wordpress - - echo 'DB Export ------> ' - mysqldump --opt --add-drop-table -h$host -u$user -p$pass $db | gzip > wp-db.sql.gz -} - -function file_backup { - backupfile="wordpress-backup.tar" - - echo 'File Backup --- building tar File...' - tar -cf $backupfile ~/wp* - echo '+DONE' -} - - -echo '-------------------------------------------' -echo 'Tolles Backup Script' -echo '-------------------------------------------' - -backupdir=backup - -cd ~ ; mkdir $backupdir && cd $backupdir || { echo "FEHLER!!!!"; exit 1 } - -# Funktionsaufrufe -db_backup -file_backup diff --git a/beispiele/17/wp-backup/backup.timer b/beispiele/17/wp-backup/backup.timer new file mode 100644 index 0000000..9619dcf --- /dev/null +++ b/beispiele/17/wp-backup/backup.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Tägliches Wordpress Backup + +[Timer] +OnCalender=daily + +[Install] +WantedBy=basic.target \ No newline at end of file diff --git a/beispiele/17/wp-backup/install.sh b/beispiele/17/wp-backup/install.sh new file mode 100644 index 0000000..f2f145a --- /dev/null +++ b/beispiele/17/wp-backup/install.sh @@ -0,0 +1,46 @@ +# install script + +function dialog1 { + BACKUPFILE=$(whiptail --inputbox "Backup Dateiname ohne Endung " 8 78 Name --title "Dateiname" 3>&1 1>&2 2>&3) + check_exit_status +} + +function dialog2 { + BACKUPZIEL=$(whiptail --inputbox "Backup Ziel?" 8 78 localhost --title "rsync Backupziel" 3>&1 1>&2 2>&3) + check_exit_status +} + +function check_exit_status { + exitstatus=$? + + if [ $exitstatus = 1 ]; then + echo "User selected Cancel." + exit 1 + fi +} + + +# Inhalt von backup.service +function install_service { + +# das HERE Document darf nicht eingerückt sein. +SERVICE=$(cat < /etc/systemd/system/backup.service + systemctl enable --now backup.timer +} + + +#funktions aufrufe +dialog1 +dialog2 +install_service diff --git a/beispiele/17/wp-backup/wp-backup.sh b/beispiele/17/wp-backup/wp-backup.sh new file mode 100644 index 0000000..b86315b --- /dev/null +++ b/beispiele/17/wp-backup/wp-backup.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +BACKUPFILE=$1 +BACKUPZIEL=$2 + +NOW="$(date +"%d-%m-%Y")" + +function db_backup { + # Vars + host=localhost + user=XXXXXXX + pass=XXXXXXX + db=wordpress + + mysqldump --opt --add-drop-table -h$host -u$user -p$pass $db wp-db.sql +} + +function file_backup { + cd /home/dany/local-dev/wp + tar -cJf ~/tmp/$BACKUPFILE-$NOW.tar.xz wp-content/themes wp-content/uploads #./wp-db-$NOW.sql +} + +function upload { + /usr/bin/rsync -aze 'ssh -p 64322 -i /home/dany/.ssh/server-key' /home/dany/tmp/$BACKUPFILE-$NOW.tar.xz server-name-hier:/home/dany/backups/* >> backup.log 2>&1 +} + +# Funktionsaufrufe +dialog1 +dialog2 +db_backup +file_backup +upload \ No newline at end of file