1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2025-04-07 20:08:03 -05:00
random/impfilesbk_server
2025-03-21 15:30:15 -05:00

139 lines
7.6 KiB
Bash

#!/bin/sh
# This script backs up some important stuff
# This is the version for my home server
# force script to run as specific user
if [ "$(id -u)" -eq 0 ]; then
exec sudo -H -u sintan $0 "$@"
fi
# Exit the whole script when ctrl+c is pressed
set -e
# Run only one instance of this script at one time
[ "${BKLOCKER}" != "running" ] && exec env BKLOCKER="running" flock -en "/tmp/impfilesbk.lock" "$0" "$@" || :
# Setup location for home and backup directory
HMDIR="/home/sintan"
BKDIR="/mnt/storage"
mkdir -p "/home/sintan/TempStorage/impfilesbk-logs/"
LGFILE="/home/sintan/TempStorage/impfilesbk-logs/$(date -Idate).log"
echo $(date) "| Backing up PhotoPrism index..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/photoprism/storage/index-backup.sql" "$BKDIR/Programs/Docker/PhotoPrism/index-backup-"$(date +%A)".sql" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up arr index..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/arr/config_sonarr/Backups/" "$BKDIR/Programs/Docker/arr-backups/sonarr/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/arr/config_prowlarr/Backups/" "$BKDIR/Programs/Docker/arr-backups/prowlarr/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up qBittorrent config..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/qbt/qbt-config/" "$BKDIR/Programs/Docker/qBittorrent-config/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/qbt-private/qbt-config/" "$BKDIR/Programs/Docker/qBittorrent2-config/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Caddyfiles..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/caddy/Caddyfiles/" "$BKDIR/Programs/Docker/Caddyfiles/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up cloudfalred config..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/cloudflared/config/" "$BKDIR/Programs/Docker/cloudflared-config/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo $(date) "| Backing up gpodder2go config..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/gpodder/data/" "$BKDIR/Programs/Docker/gpodder2go-data/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Navidrome db..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/navidrome/data/navidrome.db" "$BKDIR/Programs/Docker/navidrome.db" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Jellyfin config..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/jellyfin/config/" "$BKDIR/Programs/Docker/jellyfin-config/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Forgejo data..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Docker/forgejo/forgejo-data" "$HMDIR/Docker/forgejo/postgres-data" "$BKDIR/Programs/Docker/forgejo-config/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Chhoto URL data..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "vps-rsync:/home/admin/docker/chhoto-url/" "$BKDIR/Programs/Docker/chhoto-url/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Docker compose files..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats --prune-empty-dirs -f '- /*/*/' "$HMDIR/Docker/" "$BKDIR/Programs/Docker/DockerCompose/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Pictures..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Pictures/" "$BKDIR/Pictures/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/TempStorage/DCIM/" "$BKDIR/TempStorage/DCIM/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up Videos..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats --prune-empty-dirs -f '- /*/*/' "$HMDIR/Videos/" "$BKDIR/Videos/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo $(date) "| Backing up some dotfiles..." | tee -a "$LGFILE"
rsync -aAXH --delete --stats --quiet --no-links --exclude={'*cache*','*Cache*'} --delete-excluded "$HMDIR/.config/" "$BKDIR/dotfiles/server/[dot]config/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/.bash_profile" "$BKDIR/dotfiles/server/[dot]bash_profile" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/.bashrc" "$BKDIR/dotfiles/server/[dot]bashrc" | tee -a "$LGFILE"
# rsync -aAXH --delete --stats "$HMDIR/.Xresources" "$BKDIR/dotfiles/server/[dot]Xresources" | tee -a "$LGFILE"
# rsync -aAXH --delete --stats "$BKDIR/dotfiles/[dot]local_bin_personal/" "$HMDIR/.local/bin/personal/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/.ssh/" "$BKDIR/dotfiles/server/[dot]ssh/" | tee -a "$LGFILE"
echo $'\n'$(date) "| Done!" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
echo "--- Now backing up to the DAS ---" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
HMDIR=/mnt/storage
BKDIR_P=/tank1/personal
BKDIR_M=/tank1/media
rsync -aAXH --delete --stats "$HMDIR/Pictures/" "$BKDIR_P/Pictures/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Videos/" "$BKDIR_P/Videos/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Academics/" "$BKDIR_P/Academics/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Zotero/" "$BKDIR_P/Zotero/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Documents/" "$BKDIR_P/Documents/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Code/" "$BKDIR_P/Code/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/TempStorage/DCIM/" "$BKDIR_P/TempStorage/DCIM/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/TempStorage/MobileSS/" "$BKDIR_P/TempStorage/MobileSS/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/TempStorage/.cache/" "$BKDIR_M/TempStorage/.cache/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Programs/" "$BKDIR_P/Programs/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/dotfiles/" "$BKDIR_P/dotfiles/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Music/" "$BKDIR_M/Music/" | tee -a "$LGFILE"
rsync -aAXH --delete --stats "$HMDIR/Movies/" "$BKDIR_M/Movies/Main/" | tee -a "$LGFILE"
echo $'\n'"--------------------------------------------------" | tee -a "$LGFILE"
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | tee -a "$LGFILE"
echo "--------------------------------------------------" | tee -a "$LGFILE"
# Make the new files visible over samba
# chcon -R -t samba_share_t /mnt/storage/Programs/
# chcon -R -t samba_share_t /mnt/storage/dotfiles/server/