scripts/bash/workflow_nextcloud/sync_spaceship.sh

227 lines
9.6 KiB
Bash
Raw Normal View History

2023-02-20 16:55:34 +01:00
#!/bin/bash
2023-07-17 22:19:25 +02:00
# ----------------- documentation -----------------
2022-07-06 16:16:12 +02:00
#
# @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}
2023-07-17 22:19:25 +02:00
#
2022-07-06 16:16:12 +02:00
#
# à installer en cronjob avec:
# crontab -e
#
# m h dom mon dow command
2023-02-17 12:27:17 +01:00
# */30 * * * * bash ~/sync_spaceship.sh
2022-07-06 16:16:12 +02:00
#
2023-07-17 22:19:25 +02:00
# ----------------- configs -----------------
2023-02-06 13:28:35 +01:00
# functions_sync.sh définit les constantes utiles
2023-07-17 22:19:25 +02:00
# 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
2023-02-06 13:28:35 +01:00
LOGIN_NAS="tykayn@192.168.1.15"
2023-07-17 22:19:25 +02:00
. ~/Nextcloud/ressources/workflow_nextcloud/workflow_variables.sh
. ~/Nextcloud/ressources/workflow_nextcloud/install/functions_tk.sh
2023-02-20 18:03:27 +01:00
. ~/Nextcloud/ressources/workflow_nextcloud/install/functions_sync.sh
2022-07-06 16:16:12 +02:00
logDate ' start backup script from sync_spaceship script'
logDate "${pwd} sync_spaceship.sh"
2023-07-17 22:19:25 +02:00
#logDate ' stop all rsync jobs'
#killall rsync;
2022-07-06 16:16:12 +02:00
2023-02-06 13:28:35 +01:00
2022-07-06 16:16:12 +02:00
# ------------------
2023-07-17 22:19:25 +02:00
logDate ' copie de config actuelle'
cp ~/.bash_aliases $WORKFLOW_PATH/install/
cp ~/.emacs $WORKFLOW_PATH/install/
cp ~/.gitconfig $WORKFLOW_PATH/install/
2022-07-06 16:16:12 +02:00
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
2023-07-17 22:19:25 +02:00
dpkg --get-selections > $WORKFLOW_PATH/install/list_of_debian_apt_packages.txt
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
#bash archive_from_nextcloud.sh
2023-02-06 13:28:35 +01:00
# --------- copier la home dans les archives ------------
2022-07-06 16:16:12 +02:00
logDate 'update home backup';
2023-07-17 22:19:25 +02:00
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
2022-07-06 16:16:12 +02:00
# --------- sauver les dossiers de développement dans l'archive stockage syncable sans supprimer les projets présents -------- #
2023-07-17 22:19:25 +02:00
#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[@]}"
2022-07-06 16:16:12 +02:00
# ----------------------------------------------------------------------
# --------- disques -------- #
2023-07-17 22:19:25 +02:00
# - blue 4To (squatt à thalmont)
2022-07-06 16:16:12 +02:00
# - brossadent 4To
# - chaton 5To (usb boitier)
# - lilia 4To
# - louisbraille 4To
# - brossadent 4To (squatt à vovo)
# -|(disque sur dock)
# |--|
2023-07-17 22:19:25 +02:00
# | |- moonmoon 3To
2022-07-06 16:16:12 +02:00
#  | |- rondoudou 1To --- non chiffré
# |
# |--|
# |- catwoman 4To (dans le NAS)
# - Taiga 1To
echo "le log de backup se situe dans : $LOG_FILE_BACKUP_DATES"
2023-07-17 22:19:25 +02:00
# --------- mettre à jour les borg backup des serveurs distants -------- #
# getWebServersBorg;
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# --- 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"
2022-07-06 16:16:12 +02:00
# --------- disques avec beaucoup de place -------- #
# --------- disques chiffrés -------- #
2023-02-06 13:28:35 +01:00
#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 -------- #
2023-07-17 22:19:25 +02:00
# 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
2022-07-06 16:16:12 +02:00
# --------- disques de petite taille -------- #
2023-07-17 22:19:25 +02:00
# ne peuvent prendre que le stockage syncable
# ----------- small disks --------------
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# --------- autres pool ZFS -------- #
#syncfatland;
2022-07-06 16:16:12 +02:00
## possible amélioration de vitesse de rsync sur les gros dossiers
# ls $dossier_source | xargs -n1 -P4 -I% rsync -Pa % $destination
2023-07-17 22:19:25 +02:00
# ----------------- sync to NAS -----------------
2022-07-06 16:16:12 +02:00
# à destination du NAS, les borg backups perso et de serveurs
2023-07-17 22:19:25 +02:00
# 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
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# 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
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# logDate ' à destination du NAS: music';
# #rsync -avhWP /home/poule/music $LOGIN_NAS:/volume1/music --delete-before --inplace --perms
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# # 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[@]}"
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# 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[@]}"
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# 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[@]}"
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
# logDate 'en provenance du NAS: fait';
2022-07-06 16:16:12 +02:00
2023-07-17 22:19:25 +02:00
#logDate ' sauver les textes Org'
#cd ~/Nextcloud/textes/orgmode && git add . --all && git commit -m "update orgmode files" && cd -
2023-02-06 13:28:35 +01:00
2022-07-06 16:16:12 +02:00
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
2023-07-17 22:19:25 +02:00
#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
2022-07-06 16:16:12 +02:00
date -ud "@$SECONDS" | tee -a $LOG_FILE_BACKUP_DATES 2>&1
echo " " | tee -a $LOG_FILE_BACKUP 2>&1
2023-07-17 22:19:25 +02:00
echo " ---------------------------- " | tee -a $LOG_FILE_BACKUP 2>&1
2022-07-06 16:16:12 +02:00
logDate 'fin de sync_spaceship.sh';