scripts/bash/workflow_nextcloud/sync_spaceship.sh

203 lines
8.9 KiB
Bash
Raw Normal View History

2023-02-20 16:55:34 +01:00
#!/bin/bash
2022-07-06 16:16:12 +02:00
# ----------------- 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
2023-02-17 12:27:17 +01:00
# */30 * * * * bash ~/sync_spaceship.sh
2022-07-06 16:16:12 +02:00
#
# ----------------- configs -----------------
2023-02-06 13:28:35 +01:00
# functions_sync.sh définit les constantes utiles
LOGIN_NAS="tykayn@192.168.1.15"
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"
logDate ' stop all rsync jobs'
killall rsync;
2023-02-06 13:28:35 +01:00
2022-07-06 16:16:12 +02:00
# ------------------
logDate ' copie du script actuel'
2023-02-06 13:28:35 +01:00
cp ~/.bash_aliases $ARCHIVE_SYNCABLE/archivage/__scripts_syncro
cp ~/.emacs $ARCHIVE_SYNCABLE/archivage/__scripts_syncro
cp ~/Nextcloud/ressources/workflow_nextcloud/sync_spaceship.sh $ARCHIVE_SYNCABLE/archivage/__scripts_syncro
2022-07-06 16:16:12 +02:00
2023-02-17 12:27:17 +01:00
#cp ~/.bash_aliases ~/Nextcloud/ressources/workflow_nextcloud/install
#cp ~/.emacs ~/Nextcloud/ressources/workflow_nextcloud/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-02-06 13:28:35 +01:00
dpkg --get-selections>~/list_of_debian_apt_packages.txt
2022-07-06 16:16:12 +02:00
# back pictures to ARCHIVE_SYNCABLE
logDate 'copy of Nextcloud InstantUpload photos'
2023-02-17 12:27:17 +01:00
mv ~/Nextcloud/InstantUpload/Camera/* "$ARCHIVE_SYNCABLE/photos/a dispatcher" | tee -a $LOG_FILE_BACKUP 2>&1
2023-02-22 15:52:26 +01:00
mv ~/Nextcloud/inbox/instantUpload/* "$ARCHIVE_SYNCABLE/photos/a dispatcher" | tee -a $LOG_FILE_BACKUP 2>&1
mv ~/Nextcloud/inbox/instantUpload "$ARCHIVE_SYNCABLE/photos/a dispatcher" | tee -a $LOG_FILE_BACKUP 2>&1
2022-07-06 16:16:12 +02:00
echo ' ' >> $LOG_FILE_BACKUP_DATES
2023-02-06 13:28:35 +01:00
echo "### ${today} medias in $ARCHIVE_SYNCABLE/photos/$CURRENT_YEAR" >> $LOG_FILE_BACKUP_DATES
ls -l "$ARCHIVE_SYNCABLE/photos/$CURRENT_YEAR" | wc -l | tee -a $LOG_FILE_BACKUP 2>&1
2023-02-17 12:27:17 +01:00
2022-07-06 16:16:12 +02:00
logDate ' Screenshots et Download'
2023-02-06 13:28:35 +01:00
mv ~/Nextcloud/inbox/InstantUpload/Screenshots/* "$ARCHIVE_SYNCABLE/photos/screenshots" | tee -a $LOG_FILE_BACKUP 2>&1
mv ~/Nextcloud/inbox/InstantUpload/Download/* "$ARCHIVE_SYNCABLE/BAZAR" | tee -a $LOG_FILE_BACKUP 2>&1
2022-07-06 16:16:12 +02:00
logDate 'update local nextcloud to stockage syncable';
2023-02-06 13:28:35 +01:00
rsync -avhWP --perms --inplace --delete-before ~/Nextcloud/* $ARCHIVE_SYNCABLE/archivage/clouds/Nextcloud | tee -a $LOG_FILE_BACKUP 2>&1
# --------- copier la home dans les archives ------------
2022-07-06 16:16:12 +02:00
logDate 'update home backup';
2023-02-17 12:27:17 +01:00
rsync -avhWP --inplace --delete-before ~/* /home/poule/encrypted/stockage-syncable/archivage/home "${exclude_opts[@]}" --exclude 'Nextcloud' --exclude 'www' --exclude 'VirtualBox VMs' | 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 -------- #
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 à lyon)
# - 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 -------- #
2023-02-06 13:28:35 +01:00
# getWebServersBorg;
2022-07-06 16:16:12 +02:00
# --- raspberry pi ---------- #
logDate 'update local backup de domoticz vers stockage-syncable/www/backup/domoticz/synced';
2023-02-06 13:28:35 +01:00
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
# --- maj borg de stockage syncable ---------- #
upBorg;
# --------- 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 -------- #
clearDiskSyncBorg kungfu
clearDiskSyncBorg brossadent
clearDiskSyncBorg moonmoon
clearDiskSyncBorg chaton
clearDiskSyncBorg rugged
clearDiskSyncBorg louisbraille
clearDiskSyncBorg lilia
clearDiskSyncBorg blue
2022-07-06 16:16:12 +02:00
# --------- disques de petite taille -------- #
# ne peuvent prendre que le stockage syncable
# ----------- small disks --------------
# syncro vers Taiga de borg
FILE=/media/$USER/Taiga
if test -d "$FILE"; then
echo "### $FILE , Taiga exists." >> $LOG_FILE_BACKUP_DATES
logDate 'Taiga disk monté - sync borg backup';
# rsync -avhWP /home/poule/encrypted/stockage-syncable/* /media/$USER/$diskName/encrypted/stockage-syncable --perms --delete-before --inplace "${exclude_opts[@]}"
rsync -avhWP /home/poule/borg_archives/backup_land4to/* /media/tykayn/Taiga/backup_land4to --delete-before --inplace
else
echo 'Taiga disk NON monté '; >> $LOG_FILE_BACKUP_DATES
fi
# --------- 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';
2023-02-06 13:28:35 +01:00
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
logDate ' à destination du NAS: production-servers-backup';
2023-02-06 13:28:35 +01:00
#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[@]}"
2022-07-06 16:16:12 +02:00
logDate ' à destination du NAS: vidéos DL';
2023-02-06 13:28:35 +01:00
#rsync -avhWP /home/poule/videos/DOCU-CONF-YOUTUBE/* $LOGIN_NAS:/volume1/bidules_partagés/videos/DOCU-CONF-YOUTUBE --delete-before --inplace --perms
2022-07-06 16:16:12 +02:00
logDate ' à destination du NAS: vidéos';
2023-02-06 13:28:35 +01:00
#rsync -avhWP /home/poule/videos/* $LOGIN_NAS:/volume1/bidules_partagés/videos --delete-before --inplace --perms
2022-07-06 16:16:12 +02:00
logDate ' à destination du NAS: music';
2023-02-06 13:28:35 +01:00
#rsync -avhWP /home/poule/music $LOGIN_NAS:/volume1/music --delete-before --inplace --perms
2022-07-06 16:16:12 +02:00
# en provenance du NAS ----- les bidules partagés
logDate 'en provenance du NAS: bidules_partagés Documents administratifs';
2023-02-06 13:28:35 +01:00
#rsync -avhWP $LOGIN_NAS:/volume1/bidules_partagés/Documents\\\ administratifs /home/poule/encrypted/bidules_partagés_backup --delete-before --inplace --perms "${exclude_opts[@]}"
2022-07-06 16:16:12 +02:00
logDate 'en provenance du NAS: bidules_partagés Briis';
2023-02-06 13:28:35 +01:00
#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
logDate 'en provenance du NAS: bidules_partagés Mariage';
2023-02-06 13:28:35 +01:00
#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
logDate 'en provenance du NAS: bidules_partagés wulfila_home sans backups ordi';
2023-02-06 13:28:35 +01:00
#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
logDate 'en provenance du NAS: fait';
2023-02-06 13:28:35 +01:00
logDate ' sauver les textes Org'
cd ~/Nextcloud/textes/orgmode && git add . --all && git commit -m "update orgmode files" && cd -
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
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
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';