Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
content:serverbasics:server-backup [2025/03/28 19:11] – angelegt Danielcontent:serverbasics:server-backup [2025/03/29 12:22] (aktuell) – [Cron- Job] Daniel
Zeile 1: Zeile 1:
 ====== Server: Backup ====== ====== Server: Backup ======
  
-There are many ways to backup your server. As NC-AIO already has Borg, you may use Borg for a complete Backup of your system.+There are many ways to backup your server. As NC-AIO already has Borg, you may use Borg for a complete Backup of your system. The docs can be found here: [[https://borgbackup.readthedocs.io/en/stable/|https://borgbackup.readthedocs.io/en/stable/]] 
 + 
 +You need to perform everything as root. So login as root somehow (maybe use ''sudo -i''
 +===== Create Borg Repository ===== 
 + 
 +First, create the Directories: 
 + 
 +  * /backup (should already be there by NC-AIO) 
 +  * /backup/borg/root 
 + 
 +Please refer to the Documentations of Borg found at [[https://borgbackup.readthedocs.io/en/stable/usage/init.html|https://borgbackup.readthedocs.io/en/stable/usage/init.html]] to create a Repository. You can also use some graphical tool like vorta for this - i did, while it will help to setup borg. 
 + 
 +For me, i chose the location ''/backup/borg/root''  as repository. I included the key, so that i only needed a new passphrase to access the repository: 
 +<code> 
 + 
 +borg init --encryption repokey-blake2 /backup/borg/root 
 + 
 +</code> 
 + 
 +===== Setup a Script ===== 
 + 
 +Create the Directory /root/backup and add a new file ''named borg_backup_root.sh''  there with the contents: 
 + 
 +<file> 
 +#!/bin/bash 
 +# Make Borg Backup of Root and all what is needed for Base-System 
 +cd /root/backup 
 + 
 +#Vars 
 +export BORG_PASSPHRASE='yoursecretpassphrase' 
 +ARCHIVNAME="backup-$(date '+%Y%m%d_%H%M%S')" 
 +REPONAME="/backup/borg/root" 
 + 
 +echo "Starting Backup of Root with Borg" 
 +#This will create a btrfs readonly snapshot of root in the directory /root_snapshot 
 +/sbin/btrfs subvolume snapshot -r / /root_snapshot 
 +echo "Creating Archive ${ARCHIVNAME} in ${REPONAME}..." 
 +/usr/bin/borg create --warning --show-version --list --filter=AM --show-rc -s -C lz4 --exclude-from /root/backup/excludelist ${REPONAME}::${ARCHIVNAME} /root_snapshot /boot/grub2 /i386-pc /boot/grub2/x86_64-efi /opt /root /srv /tmp /usr/local /var /boot/efi /home 
 +RETURNCODE=$? 
 +/sbin/btrfs subvolume delete /root_snapshot 
 +if [ ${RETURNCODE} -ne 0 ]; then 
 + echo "Some ERROR with Borg. Stopping execution." 
 + exit ${RETURNCODE} 
 +fi 
 + 
 +echo "Pruning Archives" 
 +/usr/bin/borg prune --show-rc --warning --progress --keep-hourly 2 --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --keep-yearly 2 -a pcserver2023-* --keep-within 10H ${REPONAME} 
 + 
 +echo "Checking this Archive (${ARCHIVNAME})" 
 +/usr/bin/borg check --show-rc ${REPONAME}::${ARCHIVNAME} 
 +echo "Done Backup root" 
 + 
 +</file> 
 + 
 +Second, add n new File named ''excludelist''  and put in e.g: 
 + 
 +<file> 
 +#This list was created by Vorta as root (manually copying preview of exlcudes) 
 +
 +# custom added rules 
 +/home/docker/nextcloud_data/ 
 +/home/docker/.local/share/docker/ 
 +/var/lib/mysql/ 
 + 
 +# flatpak-builder 
 +fm:*.flatpak-builder 
 + 
 +# recycle-bin-trash 
 +fm:*/.local/share/Trash/
 +fm:*/.Trash/
 +fm:*/.Trash-*/
 + 
 +# chromium-cache 
 +fm:*/.config/chromium/*/Application Cache 
 +fm:*/.config/chromium/*/History Index * 
 +fm:*/.config/chromium/*/Local Storage 
 +fm:*/.config/chromium/*/Service Worker/CacheStorage 
 +fm:*/.config/chromium/*/Session Storage 
 +fm:*/.config/chromium/GrShaderCache 
 +fm:*/.config/chromium/GraphiteDawnCache 
 +fm:*/.config/chromium/ShaderCache 
 +fm:*/.var/app/org.chromium.Chromium/cache 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/*/Application Cache 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/*/History Index * 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/*/Local Storage 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/*/Service Worker/CacheStorage 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/*/Session Storage 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/GrShaderCache 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/GraphiteDawnCache 
 +fm:*/.var/app/org.chromium.Chromium/config/chromium/ShaderCache 
 +fm:*/snap/chromium/*/.config/chromium/*/Service Worker/CacheStorage 
 +fm:*/snap/chromium/*/.local/share 
 +fm:*/snap/chromium/common/.cache 
 + 
 +# google-chrome-cache 
 +fm:*/.cache/google-chrome 
 +fm:*/.cache/google-chrome-unstable 
 +fm:*/.config/google-chrome-unstable/*/Application Cache 
 +fm:*/.config/google-chrome-unstable/*/History Index * 
 +fm:*/.config/google-chrome-unstable/*/Local Storage 
 +fm:*/.config/google-chrome-unstable/*/Service Worker/CacheStorage 
 +fm:*/.config/google-chrome-unstable/*/Session Storage 
 +fm:*/.config/google-chrome-unstable/GrShaderCache 
 +fm:*/.config/google-chrome-unstable/GraphiteDawnCache 
 +fm:*/.config/google-chrome-unstable/ShaderCache 
 +fm:*/.config/google-chrome/*/Application Cache 
 +fm:*/.config/google-chrome/*/History Index * 
 +fm:*/.config/google-chrome/*/Local Storage 
 +fm:*/.config/google-chrome/*/Service Worker/CacheStorage 
 +fm:*/.config/google-chrome/*/Session Storage 
 +fm:*/.config/google-chrome/GrShaderCache 
 +fm:*/.config/google-chrome/GraphiteDawnCache 
 +fm:*/.config/google-chrome/ShaderCache 
 +fm:*/.var/app/com.google.Chrome/cache 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/*/Feature Engagement Tracker 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/*/Local Storage 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/*/Service Worker/CacheStorage 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/*/Session Storage 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/GrShaderCache 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/GraphiteDawnCache 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/Safe Browsing 
 +fm:*/.var/app/com.google.Chrome/config/google-chrome/ShaderCache 
 +fm:*/.var/app/com.google.ChromeDev/cache 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/*/Feature Engagement Tracker 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/*/Local Storage 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/*/Service Worker/CacheStorage 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/*/Session Storage 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/GrShaderCache 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/GraphiteDawnCache 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/Safe Browsing 
 +fm:*/.var/app/com.google.ChromeDev/config/google-chrome-unstable/ShaderCache 
 + 
 +# firefox-cache 
 +fm:*/.cache/mozilla/firefox 
 +fm:*/.mozilla/firefox/*/.parentlock 
 +fm:*/.mozilla/firefox/*/Cache 
 +fm:*/.mozilla/firefox/*/XPC.mfasl 
 +fm:*/.mozilla/firefox/*/XUL.mfasl 
 +fm:*/.mozilla/firefox/*/blocklist.xml 
 +fm:*/.mozilla/firefox/*/compreg.dat 
 +fm:*/.mozilla/firefox/*/extensions.cache 
 +fm:*/.mozilla/firefox/*/extensions.ini 
 +fm:*/.mozilla/firefox/*/extensions.rdf 
 +fm:*/.mozilla/firefox/*/extensions.sqlite 
 +fm:*/.mozilla/firefox/*/extensions.sqlite-journal 
 +fm:*/.mozilla/firefox/*/minidumps 
 +fm:*/.mozilla/firefox/*/pluginreg.dat 
 +fm:*/.mozilla/firefox/*/urlclassifier3.sqlite 
 +fm:*/.mozilla/firefox/*/xpti.dat 
 +fm:*/snap/firefox/common/.cache 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/.parentlock 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/XPC.mfasl 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/XUL.mfasl 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/blocklist.xml 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/compreg.dat 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/extensions.cache 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/extensions.ini 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/extensions.rdf 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/extensions.sqlite 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/extensions.sqlite-journal 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/minidumps 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/pluginreg.dat 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/urlclassifier3.sqlite 
 +fm:*/snap/firefox/common/.mozilla/firefox/*/xpti.dat 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/.parentlock 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/XPC.mfasl 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/XUL.mfasl 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/blocklist.xml 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/compreg.dat 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/extensions.cache 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/extensions.ini 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/extensions.rdf 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/extensions.sqlite 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/extensions.sqlite-journal 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/minidumps 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/pluginreg.dat 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/urlclassifier3.sqlite 
 +fm:*/.var/app/org.mozilla.firefox/.mozilla/firefox/*/xpti.dat 
 +fm:*/.var/app/org.mozilla.firefox/cache 
 + 
 +</file> 
 + 
 +===== Cron- Job ===== 
 + 
 +To setup a cron, add a new File named borg_backup_root_cron.sh with content: 
 + 
 +<file> 
 +#!/bin/bash 
 +# Execute Borg Backup with cron 
 +cd /root/backup 
 +./borg_backup_root.sh> $0.log 2>&
 +cat $0.log 
 + 
 +</file> 
 + 
 +And insert this script to crontab with crontab -e: 
 + 
 +<file> 
 +0 1 * * * /root/backup/borg_backup_root_cron.sh 
 + 
 +</file> 
 + 
 +Thats it, your Backup will perform on a daily base. You could also do more backups if you like.
  
  
  • content/serverbasics/server-backup.1743189106.txt.gz
  • Zuletzt geändert: 2025/03/28 19:11
  • von Daniel