Skip to content

Instantly share code, notes, and snippets.

@relkai
Last active September 3, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relkai/a440ba5e63904ead9b8d1f7c0de3e631 to your computer and use it in GitHub Desktop.
Save relkai/a440ba5e63904ead9b8d1f7c0de3e631 to your computer and use it in GitHub Desktop.
Fullback inkl. Datenbank (dbbackup.sh erforderlich)
#!/bin/bash
# Variablen festlegen
backup_root="/mnt/backup"
backup_dir="${backup_root}/filesystem"
backup_db_dir="${backup_root}/db"
retention="2W"
script_path="/usr/local/sbin"
# Backup-Partition einmounten
if [[ "$(df | grep $backup_root)" = "" ]]; then
mount ${backup_root}
backup_mounted="y"
echo "* Backup Directory eingemountet"
else
echo "* Backup Directory ist bereits gemountet"
fi
df | grep ${backup_root}
echo
# Boot-Partition einmounten
if [[ "$(df | grep /boot)" = "" ]]; then
mount /boot
boot_mounted="y"
echo "* Boot Directory eingemountet"
else
echo "* Boot Directory ist bereits gemountet"
fi
df | grep /boot
echo
# Loeschen veralteter Backups
echo "* Alte differential Filesystem-Backups werden geloescht"
rdiff-backup --force --remove-older-than ${retention} ${backup_dir}
echo
# DB-Backup ausfuehren
echo "* Fuehre DB-Backup aus"
${script_path}/dbbackup
echo "* Abgeschlossen: $(date)"
echo
# Filesystem-Backup ausfuehren
echo "* Fuehre Filesystem-Backup aus"
rdiff-backup --print-statistics --exclude-sockets \
--exclude "/proc/*" \
--exclude "/sys/*" \
--exclude "/dev/*" \
--exclude "/tmp/*" \
--exclude "/mnt/*/*" \
--exclude "/var/cache/squid/*" \
--exclude "/var/tmp/*" \
--exclude "/usr/portage/*" \
--include "/usr/src/linux-*/.config" \
--exclude "/usr/src/linux-*" \
::/ ${backup_dir}
echo "* Abgeschlossen: $(date)"
echo
# Festplatten synchronisieren
echo "* Festplatten werden synchronisiert"
sync
echo
# Loeschen alter Log-Dateien
find ${backup_root}/log/ -mtime +14 -exec rm {} \;
# Backup Directory ausmounten, wenn es durch dieses Script eingemounted wurde
if [[ "${backup_mounted}" = "y" ]]; then
umount ${backup_root}
echo "* Backup Directory ausgemountet"
echo
fi
# Boot Directory ausmounten, wenn es durch dieses Script eingemounted wurde
if [[ "${boot_mounted}" = "y" ]]; then
umount /boot
echo
echo "* Boot Directory ausgemountet"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment