Linux : ~/ sichern mit Borgbackup
Ich habe hier einiges an sensible Daten in meinem Homeverzeichnis die ich nicht verlieren möchte. Deswegen habe ich mir ein borgbackup eingerichtet das mir alle 30 Minuten ein Backup auf meine zweite HDD schiebt. Da beide HDD bei mir mit LUKS verschlüsselt sind ist das Repo nicht gesondert gesichert.
Installieren von borgbackup
Sollte man hier auf ein NFS oder ein anderes unverschlüsseltes Ziel sichern rate ich zu einer encryption !
Installieren von borgbackup
sudo apt install borgbackupdann richten wir auf der zweiten HDD ein Repo ein. Das hab ich dann so gemacht
mkdir -p /media/chris/hdd2/backup cd /media/chris/hdd2/backupnatürlich muss der mountpoint eurer Umgebung angepasst werden. Jetzt initialisieren wir das REPO für das Backup
borg init -e none /media/chris/hdd2/backup
Nochmal der Hinweis -e none kommt bei mir nur zum Einsatz da ALLE HDDs in meinem Notebook mit LUKS verschlüsselt sind
Ab jetzt kann man Backups in das Verzeichnis machen. Ich hab mir hier das ein Script zusammengebaut !/bin/bash
_bbin=$(which borg)
_tbin=$(which tee)
# -----------------------------------------------------------------
# VARs
# -----------------------------------------------------------------
_own_path=$(dirname $(readlink -f ${0}))
_mnt_path="" # mount point 2 hdd
_src_path="" # was soll gesichert werden ? z.B. /home/test sichert das komplette Homeverzeichniss
_exclude="" # welche Verzeichnisse sollten nicht gesichert werden ? z.B. /home/test/Downloads
_tar_path="" # Wohin wird gesichert
_repo_name="HOME-$(date '+%Y%m%d-%H%M%S')" # Name der Sicherung
_borg_para="-v --stats -C lz4" # Parameter für das Borgbackup
_borg_log="${_own_path}/logs/borg.log" # wo liegt das log
# -----------------------------------------------------------------
# parameter for borg prune
# https://borgbackup.readthedocs.io/en/stable/usage/prune.html
KH=2 # keep hourly
KD=2 # keep daily
KW=4 # keep weekly
KM=3 # keep monthly
# create prune parameter
_borg_prune=""
if [ ${KH} != 0 ]; then
_borg_prune="${_borg_prune} --keep-hourly=${KH}"
fi
if [ ${KD} != 0 ]; then
_borg_prune="${_borg_prune} --keep-daily=${KD}"
fi
if [ ${KW} != 0 ]; then
_borg_prune="${_borg_prune} --keep-weekly=${KW}"
fi
if [ ${KM} != 0 ]; then
_borg_prune="${_borg_prune} --keep-monthly=${KM}"
fi
# -----------------------------------------------------------------
# check folders
if [ ! -d "${_own_path}/logs" ]; then
mkdir -p "${_own_path}/logs"
fi
# -----------------------------------------------------------------
# write all to logfile
exec > >(${_tbin} -i ${_borg_log})
exec 2>&1
# -----------------------------------------------------------------
_chk_mnt=$(mount | grep -iq "${_mnt_path}")
if [ $? -eq 0 ]; then
echo -e "\n#----------------------------------------------------------------------------------------------#"
echo "############### borg create ####################################################################"
echo -e "#----------------------------------------------------------------------------------------------#\n"
${_bbin} create ${_borg_para} ${_tar_path}::${_repo_name} ${_src_path}
if [ $? -eq 0 ]; then
echo -e "\n#----------------------------------------------------------------------------------------------#"
echo "############### borg prune #####################################################################"
echo -e "#----------------------------------------------------------------------------------------------#\n"
${_bbin} prune --list ${_tar_path} ${_borg_prune}
echo -e "\n#----------------------------------------------------------------------------------------------#"
echo "############### borg list ######################################################################"
echo -e "#----------------------------------------------------------------------------------------------#\n"
${_bbin} list ${_tar_path}
echo -e "\n#----------------------------------------------------------------------------------------------#"
echo "############### borg info ######################################################################"
echo -e "#----------------------------------------------------------------------------------------------#\n"
${_bbin} info ${_tar_path}
fi
exit 0
else
echo "$(date '%Y%m%d %H:%M') - ${_mnt_path} is not mounted exited" >> ${_borg_log}
exit 1
fi
diese Script legt man sich jetzt irgendwo auf die Platte und ruft es in crontab auf z.B. alle 30 Minuten*/30 * * * * /scripts/create_borg_backup.sh
