From 125256558b8a618f5a8c1d6cdd92300a3bfa31fc Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Wed, 22 Feb 2017 22:06:19 +0100 Subject: [PATCH] init repo --- backup/gitea/backups.mysql.passwd | 1 + backup/gitea/gitea-backup.sh | 36 +++++++++++++++++++ backup/gitlab/backup-thetown-gitlab.py | 50 ++++++++++++++++++++++++++ backup/nextcloud/backups.mysql.passwd | 1 + backup/nextcloud/nextcloud-backup.sh | 35 ++++++++++++++++++ backup/nextcloud/nextcloud.ignore | 4 +++ 6 files changed, 127 insertions(+) create mode 100644 backup/gitea/backups.mysql.passwd create mode 100644 backup/gitea/gitea-backup.sh create mode 100644 backup/gitlab/backup-thetown-gitlab.py create mode 100644 backup/nextcloud/backups.mysql.passwd create mode 100644 backup/nextcloud/nextcloud-backup.sh create mode 100644 backup/nextcloud/nextcloud.ignore diff --git a/backup/gitea/backups.mysql.passwd b/backup/gitea/backups.mysql.passwd new file mode 100644 index 0000000..7ff0efa --- /dev/null +++ b/backup/gitea/backups.mysql.passwd @@ -0,0 +1 @@ +diesIsteinStarkesPasswort \ No newline at end of file diff --git a/backup/gitea/gitea-backup.sh b/backup/gitea/gitea-backup.sh new file mode 100644 index 0000000..a5352e2 --- /dev/null +++ b/backup/gitea/gitea-backup.sh @@ -0,0 +1,36 @@ +#!/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 \ No newline at end of file diff --git a/backup/gitlab/backup-thetown-gitlab.py b/backup/gitlab/backup-thetown-gitlab.py new file mode 100644 index 0000000..1e751e4 --- /dev/null +++ b/backup/gitlab/backup-thetown-gitlab.py @@ -0,0 +1,50 @@ +import os +import time +from gitlab import Gitlab + +URL = "gitlab.com" +PRIVATE_TOKEN = "" +USERNAME = "" +startedTask = time.time() + +gl = Gitlab("https://%s" % URL, PRIVATE_TOKEN) +groupsToCheck = ['TheTown'] + +gl.auth() + +gitPath = "/mnt/sata/BACKUP/Git/" +if not os.path.exists(gitPath): + exit("Git Path does not exists!") + +print("Pulling Projects...") +pullList = [] +for grp in gl.groups.list(): + if [s for s in groupsToCheck if grp.name in s]: + projects = grp.projects.list(all=True) + for p in projects: + path = "%s/%s" % (grp.name, p.name) + pullList.append(path) +print("Pulled %s Projects..." % len(pullList)) + +print("Starting Clone Task...") +startedClone = time.time() +os.chdir(gitPath) +for singleClone in pullList: + pPath = gitPath + singleClone + print("Check Project State") + if not os.path.exists(pPath): + print("%s is a new Project. Creating Folder and init Repo..." % singleClone) + os.makedirs(pPath) + os.chdir(pPath) + os.system("git init") + else: + print("%s project is not new. switching Directory" % singleClone) + + os.chdir(pPath) + print("Start Cloning %s" % singleClone) + os.system("git pull https://%s:%s@%s/%s.git" % (USERNAME, PRIVATE_TOKEN, URL, singleClone)) + print("Cloning %s Complete" % singleClone) + os.chdir(gitPath) +print("Clone Complete. Clone ran %ss..." % (time.time() - startedClone)) + +print("Finished. Ran %ss..." % (time.time() - startedTask)) diff --git a/backup/nextcloud/backups.mysql.passwd b/backup/nextcloud/backups.mysql.passwd new file mode 100644 index 0000000..7ff0efa --- /dev/null +++ b/backup/nextcloud/backups.mysql.passwd @@ -0,0 +1 @@ +diesIsteinStarkesPasswort \ No newline at end of file diff --git a/backup/nextcloud/nextcloud-backup.sh b/backup/nextcloud/nextcloud-backup.sh new file mode 100644 index 0000000..e10abb5 --- /dev/null +++ b/backup/nextcloud/nextcloud-backup.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +RSYNC="/usr/bin/rsync" +DESTINATION="/mnt/sata/BACKUP/pi_nextcloud/git/"$1 +echo "Erstelle Backup $1 in $DESTINATION" + +echo "Erstelle Verzeichnis" +mkdir -p $DESTINATION + +sleep 1 + +RSYNC_SOURCE="backups@192.168.25.11:/home/git/" +# ssh-keygen -t rsa +# ssh-copy-id -i /root/.ssh/id_rsa.pub backups@192.168.25.11 +RSYNC_SSHKEY="/root/.ssh/id_rsa" +RSYNC_IGNORE="/root/nextcloud.ignore" +echo "Starte RSYNC mit Passwort aus $RSYNC_SSHKEY" +rsync -zavx -e 'ssh -i '$RSYNC_SSHKEY' -p22' \ + --rsync-path="$RSYNC" \ + --exclude-from="$RSYNC_IGNORE" \ + --numeric-ids \ + --delete -r $RSYNC_SOURCE $DESTINATION +echo "RSYNC beendet" + +sleep 1 + +echo "Erstelle Datenbank Datei" +mkdir -p $DESTINATION/db +mysqldump -h 192.168.25.11 --user=backups --password=hieristeinkuglespasswort --all-databases --lock-tables | bzip2 > $DESTINATION/db/database.sql.bz2 +echo "Datenbank gesichert" + +sleep 1 + +echo "Beende..." +exit 0 diff --git a/backup/nextcloud/nextcloud.ignore b/backup/nextcloud/nextcloud.ignore new file mode 100644 index 0000000..8bf8f69 --- /dev/null +++ b/backup/nextcloud/nextcloud.ignore @@ -0,0 +1,4 @@ +dash/ +share/ +phpmyadmin/ +