17 übung
This commit is contained in:
8
beispiele/17/wp-backup/backup.timer
Normal file
8
beispiele/17/wp-backup/backup.timer
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Tägliches Wordpress Backup
|
||||
|
||||
[Timer]
|
||||
OnCalender=daily
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
46
beispiele/17/wp-backup/install.sh
Normal file
46
beispiele/17/wp-backup/install.sh
Normal file
@@ -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 <<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
|
32
beispiele/17/wp-backup/wp-backup.sh
Normal file
32
beispiele/17/wp-backup/wp-backup.sh
Normal file
@@ -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
|
Reference in New Issue
Block a user