From c35a816641703e4b33ac95edb3e7d6a324288ced Mon Sep 17 00:00:00 2001 From: piccihud Date: Sat, 9 Dec 2023 19:52:37 +0100 Subject: [PATCH] aggiunto borg.md --- linux/borg.md | 153 ++++++++++++++++++++++++++++++++++ linux/filesystem/rsnapshot.md | 6 ++ 2 files changed, 159 insertions(+) create mode 100644 linux/borg.md create mode 100644 linux/filesystem/rsnapshot.md diff --git a/linux/borg.md b/linux/borg.md new file mode 100644 index 0000000..51503a5 --- /dev/null +++ b/linux/borg.md @@ -0,0 +1,153 @@ +# borgbackup + +In Debian e derivate, installare il pacchetto col comando: + +```bash +$ sudo apt install borgbackup -y +``` + +## Inizializzazione del repository + +Per inizializzare il repository, criptato tramite una password: + +```bash +$ borg init --encryption=keyfile /path/to/repo +``` +## Backup + +Per eseguire un backup manualmente + +```bash +$ borg create --stats --list --progress /path/to/repo::25-11-2023 /path/to/source/ +``` +dove `--stats` permette di stampare statistiche aggiuntive sull'archivio, mentre l'opzione `--list` di visualizzare la lista degli oggetti inseriti nell'archivio. + +Col flag `--compression` è possibile impostare anche il livello di compressione. Vedere: [Backup compression](https://borgbackup.readthedocs.io/en/stable/quickstart.html#backup-compression) + +È possibile anche visualizzare la lista dei backup: + +```bash +borg list /path/to/repo +``` + +## Restore + +Per ripristinare un backup, nella cartella corrente: + +```bash +$ borg extract -v --list /path/to/repo/::25-11-2023 +``` + +L'opzione `--dry-run` permette di vedere cosa verrebbe estratto, ma senza che sia veramente estratto. + +Ulteriori esempi: + +```bash +# Extract entire archive +$ borg extract /path/to/repo::my-files + +# Extract entire archive and list files while processing +$ borg extract --list /path/to/repo::my-files + +# Verify whether an archive could be successfully extracted, but do not write files to disk +$ borg extract --dry-run /path/to/repo::my-files + +# Extract the "src" directory +$ borg extract /path/to/repo::my-files home/USERNAME/src + +# Extract the "src" directory but exclude object files +$ borg extract /path/to/repo::my-files home/USERNAME/src --exclude '*.o' +``` + +## Montare l'archivio + +```bash +$ mkdir /tmp/borg/ + +$ borg mount /path/to/repo /tmp/borg/ + +$ ls -l /tmp/borg/ +``` + +## Retention + +Col comando `borg prune` è possibile stabilire una politica di conservazione dei backup ([https://borgbackup.readthedocs.io/en/stable/usage/prune.html](https://borgbackup.readthedocs.io/en/stable/usage/prune.html)) + +Ad esempio: + +```bash +# Keep 7 end of day, 4 additional end of week archives, and an end of month archive for every month: +borg prune --list --stats --force --keep-daily=7 --keep-weekly=4 --keep-monthly=-1 /path/to/repo + +borg prune -v /path/to/repo --stats \ + --keep-hourly=12 --keep-daily=60 --keep-weekly=12 --keep-monthly=24 +``` + +## Script + +Ecco un semplice esempio: + +```bash +#!/bin/bash + +# Percorsi +REPO_PATH=/media/user/Backup/Snapshot/ +DATA_PATH=~/ +LOG_FILE=~/logs/borg_backup.log + +export BORG_PASSPHRASE='*****************************************************' + +# Inizializzazione di Borg +borg init --encryption=keyfile /media/user/Backup/Snapshot/ + +# Creazione del backup con Borg +if borg create --stats --list --progress --compression lz4 \ + --exclude 'home/*/*.log.*' \ + --exclude 'home/*/jd2/' \ + --exclude-caches \ + --exclude '*.deb' \ + --exclude 'home/*/.cargo/' \ + --exclude 'home/*/VirtualBoxVMs/' \ + --exclude 'home/*/iso/' \ + --exclude 'home/*/Trash/' \ + $REPO_PATH::{now:'%H:%M_%d-%m-%Y'} $DATA_PATH; then + echo "$(date '+%H:%M:%S %d %b %Y'): Backup con Borg completato con SUCCESSO." >> $LOG_FILE +else + echo "$(date '+%H:%M:%S %d %b %Y'): ERRORE durante la creazione del backup con Borg." >> $LOG_FILE + exit 1 +fi + +# This command frees repository space by compacting segments +borg compact $REPO_PATH + +# Pulizia del repository +# Keep 7 end of day, 4 additional end of week archives, and an end of month archive for every month: +borg prune --list --stats --force \ + --keep-daily=7 --keep-weekly=4 --keep-monthly=-1 $REPO_PATH && borg list $REPO_PATH >> $LOG_FILE + +exit 0; +``` + +Per il montaggio: + +```bash +#! /bin/bash + +# Configurazione +export BORG_PASSPHRASE='***********************************************************' +REPO_PATH="/media/user/Backup/Snapshot" +TMP_DIR="/tmp/borg" + +# Creazione della directory temporanea +mkdir -p $TMP_DIR 2> /dev/null + +borg mount $REPO_PATH $TMP_DIR && ls -l $TMP_DIR + +exit 0 +``` + +## Collegamenti + +- [https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups](https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups) +- [https://ostechnix.com/backup-restore-files-borg-linux/](https://ostechnix.com/backup-restore-files-borg-linux/) +- [https://wiki.archlinux.org/title/Borg_backup](https://wiki.archlinux.org/title/Borg_backup) diff --git a/linux/filesystem/rsnapshot.md b/linux/filesystem/rsnapshot.md new file mode 100644 index 0000000..4329539 --- /dev/null +++ b/linux/filesystem/rsnapshot.md @@ -0,0 +1,6 @@ +# rsnapshot + +## Collegamenti + +- [https://www.debianizzati.org/backup-automatico-di-files-e-database-con-rsnapshot/](https://www.debianizzati.org/backup-automatico-di-files-e-database-con-rsnapshot/) +- [https://linuxconfig.org/guide-to-rsnapshot-and-incremental-backups-on-linux](https://linuxconfig.org/guide-to-rsnapshot-and-incremental-backups-on-linux)