Commit 9e847cb8 authored by Daniel Schubert's avatar Daniel Schubert 🎯

17 übung

parent 40ceb063
#!/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)
#!/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
[Unit]
Description=Tägliches Wordpress Backup
[Timer]
OnCalender=daily
[Install]
WantedBy=basic.target
\ No newline at end of file
# 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 <<EOF
[Unit]
Description=Tägliches Wordpress Backup
[Service]
ExecStart=/bin/wp-backup.sh "$BACKUPFILE" "$BACKUPZIEL"
EOF
)
cp wp-backup.sh /bin/
cp backup.timer /etc/systemd/system/
echo "$SERVICE" > /etc/systemd/system/backup.service
systemctl enable --now backup.timer
}
#funktions aufrufe
dialog1
dialog2
install_service
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment