Geänderte Dateien: - etc/systemd/system/system/chronyd.service - etc/systemd/system/system/cloud-config.target.wants/cloud-init-hotplugd.socket - etc/systemd/system/system/cloud-init.target.wants/cloud-config.service - etc/systemd/system/system/cloud-init.target.wants/cloud-final.service - etc/systemd/system/system/cloud-init.target.wants/cloud-init-local.service - etc/systemd/system/system/cloud-init.target.wants/cloud-init-main.service - etc/systemd/system/system/cloud-init.target.wants/cloud-init-network.service - etc/systemd/system/system/dbus-org.freedesktop.timesync1.service - etc/systemd/system/system/default.target.wants/wtmpdb-update-boot.service - etc/systemd/system/system/getty.target.wants/getty@tty1.service - etc/systemd/system/system/hibernate.target.wants/grub-common.service - etc/systemd/system/system/hybrid-sleep.target.wants/grub-common.service - etc/systemd/system/system/multi-user.target.wants/chrony.service - etc/systemd/system/system/multi-user.target.wants/console-setup.service - etc/systemd/system/system/multi-user.target.wants/cron.service - etc/systemd/system/system/multi-user.target.wants/e2scrub_reap.service - etc/systemd/system/system/multi-user.target.wants/fail2ban.service - etc/systemd/system/system/multi-user.target.wants/grub-common.service - etc/systemd/system/system/multi-user.target.wants/networking.service - etc/systemd/system/system/multi-user.target.wants/nmbd.service - etc/systemd/system/system/multi-user.target.wants/oddjobd.service - etc/systemd/system/system/multi-user.target.wants/remote-fs.target - etc/systemd/system/system/multi-user.target.wants/rsyslog.service - etc/systemd/system/system/multi-user.target.wants/samba-ad-dc.service - etc/systemd/system/system/multi-user.target.wants/smbd.service - etc/systemd/system/system/multi-user.target.wants/ssh.service - etc/systemd/system/system/multi-user.target.wants/sssd.service - etc/systemd/system/system/multi-user.target.wants/unattended-upgrades.service - etc/systemd/system/system/multi-user.target.wants/winbind.service - etc/systemd/system/system/multi-user.target.wants/zfs.target - etc/systemd/system/system/network-online.target.wants/networking.service - etc/systemd/system/system/nmb.service - etc/systemd/system/system/samba.service - etc/systemd/system/system/smb.service - etc/systemd/system/system/ssh.service.wants/sshd-keygen.service - etc/systemd/system/system/ssh.socket.wants/sshd-keygen.service - etc/systemd/system/system/sshd.service - etc/systemd/system/system/sshd.service.wants/sshd-keygen.service - etc/systemd/system/system/sshd@.service.wants/sshd-keygen.service - etc/systemd/system/system/sssd.service.wants/sssd-autofs.socket - etc/systemd/system/system/sssd.service.wants/sssd-nss.socket - etc/systemd/system/system/sssd.service.wants/sssd-pac.socket - etc/systemd/system/system/sssd.service.wants/sssd-pam.socket - etc/systemd/system/system/sssd.service.wants/sssd-ssh.socket - etc/systemd/system/system/sssd.service.wants/sssd-sudo.socket - etc/systemd/system/system/suspend-then-hibernate.target.wants/grub-common.service - etc/systemd/system/system/suspend.target.wants/grub-common.service - etc/systemd/system/system/sysinit.target.wants/apparmor.service - etc/systemd/system/system/sysinit.target.wants/keyboard-setup.service - etc/systemd/system/system/sysinit.target.wants/systemd-pstore.service - etc/systemd/system/system/sysinit.target.wants/systemd-timesyncd.service - etc/systemd/system/system/syslog.service - etc/systemd/system/system/timers.target.wants/apt-daily-upgrade.timer - etc/systemd/system/system/timers.target.wants/apt-daily.timer - etc/systemd/system/system/timers.target.wants/dpkg-db-backup.timer - etc/systemd/system/system/timers.target.wants/e2scrub_all.timer - etc/systemd/system/system/timers.target.wants/fstrim.timer - etc/systemd/system/system/timers.target.wants/logrotate.timer - etc/systemd/system/system/timers.target.wants/man-db.timer - etc/systemd/system/system/zed.service - etc/systemd/system/system/zfs-import.target.wants/zfs-import-cache.service - etc/systemd/system/system/zfs-mount.service.wants/zfs-load-module.service - etc/systemd/system/system/zfs-volumes.target.wants/zfs-volume-wait.service - etc/systemd/system/system/zfs.target.wants/zfs-import.target - etc/systemd/system/system/zfs.target.wants/zfs-load-module.service - etc/systemd/system/system/zfs.target.wants/zfs-mount.service - etc/systemd/system/system/zfs.target.wants/zfs-share.service - etc/systemd/system/system/zfs.target.wants/zfs-volumes.target - etc/systemd/system/system/zfs.target.wants/zfs-zed.service - root/backup-config/backup-config.sh - root/backup-config/run-backup-and-push.sh
87 lines
2.2 KiB
Bash
Executable File
87 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
BASE_DIR="/root/backup-config"
|
|
BACKUP_DIR="$BASE_DIR/backup"
|
|
BACKUP_SCRIPT="$BASE_DIR/backup-config.sh"
|
|
LOGFILE="/var/log/backup-config-run.log"
|
|
BRANCH="File1_Configfiles"
|
|
|
|
log() {
|
|
printf '%s %s\n' "$(date '+%F %T')" "$1" | tee -a "$LOGFILE"
|
|
}
|
|
|
|
main() {
|
|
if [[ ! -x "$BACKUP_SCRIPT" ]]; then
|
|
echo "Backup-Skript nicht gefunden oder nicht ausführbar: $BACKUP_SCRIPT" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
log "INFO: Starte Backup"
|
|
"$BACKUP_SCRIPT"
|
|
log "INFO: Backup beendet"
|
|
|
|
cd "$BACKUP_DIR"
|
|
|
|
if ! command -v git >/dev/null 2>&1; then
|
|
log "ERROR: Git ist nicht installiert"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d .git ]]; then
|
|
log "INFO: Git-Repository wird initialisiert"
|
|
git init
|
|
fi
|
|
|
|
# Branch aktivieren oder anlegen
|
|
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
|
|
git checkout "$BRANCH" >/dev/null 2>&1
|
|
log "INFO: Git-Branch aktiviert: $BRANCH"
|
|
else
|
|
if git rev-parse --verify HEAD >/dev/null 2>&1; then
|
|
git checkout -b "$BRANCH" >/dev/null 2>&1
|
|
else
|
|
git checkout --orphan "$BRANCH" >/dev/null 2>&1
|
|
fi
|
|
log "INFO: Git-Branch erstellt: $BRANCH"
|
|
fi
|
|
|
|
git add -A
|
|
|
|
if git diff --cached --quiet; then
|
|
log "INFO: Keine neuen Dateiinhalte für Commit"
|
|
else
|
|
git commit -m "Config-Backup $(hostname) $(date '+%F %T')"
|
|
log "INFO: Commit erstellt"
|
|
fi
|
|
|
|
if ! git remote get-url origin >/dev/null 2>&1; then
|
|
log "WARN: Kein Remote 'origin' konfiguriert, Push übersprungen"
|
|
exit 0
|
|
fi
|
|
|
|
# Remote-Infos aktualisieren
|
|
git fetch origin "$BRANCH" >/dev/null 2>&1 || true
|
|
|
|
# Falls der Remote-Branch noch nicht existiert
|
|
if ! git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
|
|
git push -u origin "$BRANCH"
|
|
log "INFO: Initialer Push des Branches erfolgreich"
|
|
exit 0
|
|
fi
|
|
|
|
# Prüfen, ob lokale Commits noch nicht gepusht wurden
|
|
AHEAD_COUNT="$(git rev-list --count "origin/$BRANCH..$BRANCH" 2>/dev/null || echo 0)"
|
|
|
|
if [[ "$AHEAD_COUNT" -gt 0 ]]; then
|
|
git push origin "$BRANCH"
|
|
log "INFO: Push erfolgreich ($AHEAD_COUNT lokale Commits übertragen)"
|
|
else
|
|
log "INFO: Kein Push nötig, Remote ist aktuell"
|
|
fi
|
|
}
|
|
|
|
main
|