scripts/bash/workflow_nextcloud/sync_spaceship.sh

227 lines
9.6 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ----------------- documentation -----------------
#
# @author sync_spaceship by @tykayn - contact at cipherbliss.com
#
# L'archive Borg contient stockage syncable et vise à être mise dans le NAS pour la postérité
# BORG_NEW_PASSPHRASE=mon_pass_bien_compliqué borg init -e=repokey /home/poule/borg_archives/backup_land4to
# borg create --compression lzma,9 /home/poule/borg_archives/backup_land4to::backup_land4to_{now}
#
#
# à installer en cronjob avec:
# crontab -e
#
# m h dom mon dow command
# */30 * * * * bash ~/sync_spaceship.sh
#
# ----------------- configs -----------------
# functions_sync.sh définit les constantes utiles
# le borg backup fait 1.4 To
# le stockage syncable fait
source ~/Nextcloud/ressources/workflow_nextcloud/workflow_variables.sh
source ~/Nextcloud/ressources/workflow_nextcloud/install/functions_sync.sh
source ~/Nextcloud/ressources/workflow_nextcloud/install/functions_tk.sh
LOGIN_NAS="tykayn@192.168.1.15"
. ~/Nextcloud/ressources/workflow_nextcloud/workflow_variables.sh
. ~/Nextcloud/ressources/workflow_nextcloud/install/functions_tk.sh
. ~/Nextcloud/ressources/workflow_nextcloud/install/functions_sync.sh
logDate ' start backup script from sync_spaceship script'
logDate "${pwd} sync_spaceship.sh"
#logDate ' stop all rsync jobs'
#killall rsync;
# ------------------
logDate ' copie de config actuelle'
cp ~/.bash_aliases $WORKFLOW_PATH/install/
cp ~/.emacs $WORKFLOW_PATH/install/
cp ~/.gitconfig $WORKFLOW_PATH/install/
echo ' ' >> $LOG_FILE_BACKUP_DATES
echo "### ${today} start backup script from sync_spaceship script" >> $LOG_FILE_BACKUP_DATES
echo ' ' >> $LOG_FILE_BACKUP_DATES
echo "### ${today} list of debian apt packages saved in borg_archives list_of_debian_apt_packages.txt" >> $LOG_FILE_BACKUP_DATES
# save a list of apt packages
# to restore it:
# dpkg --set-selections < list_of_debian_apt_packages.txt
dpkg --get-selections > $WORKFLOW_PATH/install/list_of_debian_apt_packages.txt
#bash archive_from_nextcloud.sh
# --------- copier la home dans les archives ------------
logDate 'update home backup';
rsync -avhWP --inplace --delete-before ~/* /home/poule/encrypted/stockage-syncable/archivage/home "${exclude_opts[@]}" \
--exclude 'Nextcloud' --exclude 'www' --exclude 'VirtualBox VMs' --exclude 'snaps' | tee -a $LOG_FILE_BACKUP 2>&1
# --------- sauver les dossiers de développement dans l'archive stockage syncable sans supprimer les projets présents -------- #
#logDate 'WWW et HTML sauver les dossiers de développement';
#rsync -avP /home/tykayn/www/* /home/poule/encrypted/stockage-syncable/www/development/html "${exclude_opts[@]}"
#rsync -avP /var/www/html/* /home/poule/encrypted/stockage-syncable/www/development/html "${exclude_opts[@]}"
# ----------------------------------------------------------------------
# --------- disques -------- #
# - blue 4To (squatt à thalmont)
# - brossadent 4To
# - chaton 5To (usb boitier)
# - lilia 4To
# - louisbraille 4To
# - brossadent 4To (squatt à vovo)
# -|(disque sur dock)
# |--|
# | |- moonmoon 3To
#  | |- rondoudou 1To --- non chiffré
# |
# |--|
# |- catwoman 4To (dans le NAS)
# - Taiga 1To
echo "le log de backup se situe dans : $LOG_FILE_BACKUP_DATES"
# --------- mettre à jour les borg backup des serveurs distants -------- #
# getWebServersBorg;
# --- maj borg de stockage syncable ---------- #
#upBorg;
#killall borg
logDate "### --------- SPACESHIP | creating borg archive at $SPACESHIP_NEW_BORG_REPO"
rm -rf ~/.cache/borg/150867528afd85114c8aba98af201a7ad8cf01869c507a87c025d2f8701040a9/lock.exclusive
rm -rf ~/.cache/borg/68b9103c6f35bfd198552cb197f149b1d05309d28ce4429f2bec8df01b453660/lock.exclusive
rm -rf ~/.cache/borg/b822ee0c0c5c7a181a3b3b7cefc6eb4f3baf9965f30bfca364c2ff92f9962de4/lock.exclusive
rm -rf ~/.cache/borg/d1c0552f96686f6d631068bc8bf0c19f2a7ff80f956dc36b0441f3d8aac78a36/lock.exclusive
# rm -rf SPACESHIP_NEW_BORG_REPO/lock.exclusive
borg create encrypted_spaceship_{now} $ARCHIVE_SYNCABLE \
/home/poule/encrypted/installateurs/installateurs_pour_ventoy \
"${exclude_opts[@]}" --progress --verbose --stats --compression zstd,9 \
| tee -a $LOG_FILE_BACKUP 2>&1
echo " " | tee -a $LOG_FILE_BACKUP 2>&1
logDate "### --------- ${today} | SPACESHIP | pruning old archives" | tee -a $LOG_FILE_BACKUP 2>&1
# nettoyage tk_backup
borg prune -v --list --stats --keep-daily=8 --keep-weekly=6 --keep-monthly=3 --keep-yearly=2 | tee -a $LOG_FILE_BACKUP 2>&1
logDate "### --------- pruning done"
# --------- disques avec beaucoup de place -------- #
# --------- disques chiffrés -------- #
#syncToBigDiskName louisbraille
#syncToBigDiskName rugged
#syncToBigDiskName moonmoon # dernier disque source pour temporisation
#syncToBigDiskName lilia
#syncToBigDiskName # chaton disque en clair pour Optiplex liness
#syncToBigDiskName blue
# --------- disques non chiffrés contenant uniquement les archives borg -------- #
# louisbraille contient l'ancienne organisation de stockage syncable
# ne laisser de borg backup land 4to que dans un seul disque
rm -rf /media/tykayn/brossadent/borg_archives/backup_land4to
rm -rf /media/tykayn/moonmoon/borg_archives/backup_land4to
#rm -rf /media/tykayn/louisbraille/borg_archives/backup_land4to
rm -rf /media/tykayn/rugged/borg_archives/backup_land4to
rm -rf /media/tykayn/chaton/borg_archives/backup_land4to
rm -rf /media/tykayn/lilia/borg_archives/backup_land4to
rm -rf /media/tykayn/blue/borg_archives/backup_land4to
syncToBigDiskName brossadent
syncToBigDiskName moonmoon
syncToBigDiskName louisbraille
syncToBigDiskName rugged
# syncToBigDiskName chaton # ce disque n'est pas chiffré, il sert à partager des médias et à voyager à liness
syncToBigDiskName lilia
syncToBigDiskName blue
clearDiskSyncBorgServer brossadent
clearDiskSyncBorgServer moonmoon
clearDiskSyncBorgServer louisbraille
clearDiskSyncBorgServer rugged
clearDiskSyncBorgServer chaton
clearDiskSyncBorgServer lilia
clearDiskSyncBorgServer blue
rsync -avP --delete-before $SPACESHIP_NEW_BORG_REPO/* /media/tykayn/Taiga/borg2
# --------- disques de petite taille -------- #
# ne peuvent prendre que le stockage syncable
# ----------- small disks --------------
# --------- autres pool ZFS -------- #
#syncfatland;
## possible amélioration de vitesse de rsync sur les gros dossiers
# ls $dossier_source | xargs -n1 -P4 -I% rsync -Pa % $destination
# ----------------- sync to NAS -----------------
# à destination du NAS, les borg backups perso et de serveurs
# logDate ' à destination du NAS: backup_land4to';
# #rsync -avhWP /home/poule/borg_archives/backup_land4to/* $LOGIN_NAS:/var/services/homes/tykayn/borg_archives/backup_land4to --delete-before --inplace --perms
# #rsync -avhWP /home/poule/cryptomator/* $LOGIN_NAS:/volume1/bidules_partagés/cryptomator --delete-before --inplace --perms
# logDate ' à destination du NAS: production-servers-backup';
# #rsync -avhWP /home/poule/borg_archives/production-servers-backup/* $LOGIN_NAS:/var/services/homes/tykayn/borg_archives/production-servers-backup --delete-before --inplace --perms --exclude="@eaDir" "${exclude_opts[@]}"
# logDate ' à destination du NAS: vidéos DL';
# #rsync -avhWP /home/poule/videos/DOCU-CONF-YOUTUBE/* $LOGIN_NAS:/volume1/bidules_partagés/videos/DOCU-CONF-YOUTUBE --delete-before --inplace --perms
# # logDate ' à destination du NAS: vidéos';
# #rsync -avhWP /home/poule/videos/* $LOGIN_NAS:/volume1/bidules_partagés/videos --delete-before --inplace --perms
# logDate ' à destination du NAS: music';
# #rsync -avhWP /home/poule/music $LOGIN_NAS:/volume1/music --delete-before --inplace --perms
# # en provenance du NAS ----- les bidules partagés
# logDate 'en provenance du NAS: bidules_partagés Documents administratifs';
# #rsync -avhWP $LOGIN_NAS:/volume1/bidules_partagés/Documents\\\ administratifs /home/poule/encrypted/bidules_partagés_backup --delete-before --inplace --perms "${exclude_opts[@]}"
# logDate 'en provenance du NAS: bidules_partagés Briis';
# #rsync -avhWP $LOGIN_NAS:/volume1/bidules_partagés/Briis /home/poule/encrypted/bidules_partagés_backup --delete-before --inplace --perms "${exclude_opts[@]}"
# logDate 'en provenance du NAS: bidules_partagés Mariage';
# #rsync -avhWP $LOGIN_NAS:/volume1/bidules_partagés/Mariage /home/poule/encrypted/bidules_partagés_backup --delete-before --inplace --perms "${exclude_opts[@]}"
# logDate 'en provenance du NAS: bidules_partagés wulfila_home sans backups ordi';
# #rsync -avhWP $LOGIN_NAS:/volume1/bidules_partagés/wulfila_home /home/poule/encrypted/other_people_content --inplace --exclude=TK-LAND --exclude=musique_tykayn --exclude=windows_backup_laptop_claire --delete-before --inplace --perms "${exclude_opts[@]}"
# logDate 'en provenance du NAS: fait';
#logDate ' sauver les textes Org'
#cd ~/Nextcloud/textes/orgmode && git add . --all && git commit -m "update orgmode files" && cd -
echo "### ${today} end" >> $LOG_FILE_BACKUP_DATES
date -ud "@$SECONDS" | tee -a $LOG_FILE_BACKUP 2>&1
echo "voir les logs: gedit $LOG_FILE_BACKUP"
echo "voir les logs des sections par dates: gedit $LOG_FILE_BACKUP_DATES"
echo " " | tee -a $LOG_FILE_BACKUP 2>&1
#echo "taille du BAZAR: $ARCHIVE_SYNCABLE/BAZAR " | tee -a $LOG_FILE_BACKUP 2>&1
#du -sch $ARCHIVE_SYNCABLE/BAZAR | tee -a $LOG_FILE_BACKUP 2>&1
# --- raspberry pi ---------- #
# logDate 'update local backup de domoticz vers stockage-syncable/www/backup/domoticz/synced';
# rsync -avhWP pi@192.168.1.2:/home/pi /home/poule/encrypted/stockage-syncable/www/backup/domoticz/synced --delete-before --inplace
date -ud "@$SECONDS" | tee -a $LOG_FILE_BACKUP_DATES 2>&1
echo " " | tee -a $LOG_FILE_BACKUP 2>&1
echo " ---------------------------- " | tee -a $LOG_FILE_BACKUP 2>&1
logDate 'fin de sync_spaceship.sh';