script-sammlung/backup/gitea/gitea-backup.sh

36 lines
890 B
Bash
Raw Normal View History

2017-02-22 22:06:19 +01:00
#!/bin/bash
HOST="192.168.25.11"
RSYNC="/usr/bin/rsync"
DB="gitea"
SOURCE="/var/www/html"
DESTINATION="/mnt/sata/BACKUP/pi_nextcloud/SCHATTENKOPIE/"$1
RSYNC_SSHKEY="/root/.ssh/id_rsa"
MYSQL_PASSWD="/root/backups.mysql.passwd"
echo "Erstelle Backup $1 in $DESTINATION"
echo "Erstelle Verzeichnis"
mkdir -p $DESTINATION
sleep 1
RSYNC_SOURCE="backups@$HOST:$SOURCE"
echo "Starte RSYNC mit Passwort aus $RSYNC_SSHKEY"
rsync -zavx -e 'ssh -i '$RSYNC_SSHKEY' -p22' \
--rsync-path="$RSYNC" \
--numeric-ids \
--delete -r $RSYNC_SOURCE $DESTINATION
echo "RSYNC beendet"
sleep 1
echo "Erstelle Datenbank Datei"
mkdir -p $DESTINATION/db
PASSWD=$(cat "$MYSQL_PASSWD" | tr -d " \t\n\r")
mysqldump -h $HOST --user=backups --password=$PASSWD --lock-tables --databases $DB | bzip2 > $DESTINATION/db/database.sql.bz2
echo "Datenbank gesichert"
sleep 1
echo "Beende..."
exit 0