This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/app/bin/home/backup

63 lines
2.8 KiB
Plaintext
Raw Normal View History

2023-08-08 16:24:15 +03:00
#!/bin/bash
# TODO: Rewrite me, maybe? <3
source /var/roothome/.config/bash/module/notify.sh
source /var/roothome/.config/bash/module/checksum.sh
2023-11-28 02:52:27 +03:00
source /var/roothome/.config/bash/module/recursive.sh
2023-08-08 16:24:15 +03:00
dow=$(/usr/bin/date +%u) # current day of week number.
date=$(/usr/bin/date +%Y%m%d%H%M) # date stamp.
path_src="/var/mnt/storage/hot" # backup src location.
path_mount="/var/mnt/storage/cold_1" # backup mount location.
path_backup="${path_mount}/backup" # backup dir location.
path_docker="${path_backup}/home" # docker backup location.
2023-08-08 16:24:15 +03:00
path_media="/var/mnt/storage/cold_1/media /var/mnt/storage/cold_2/media" # media paths.
2023-12-11 16:56:09 +03:00
# Check if backup drive is mounted.
if [ ! -f "${path_mount}"/.mount ]; then
echo "Backup : ${path_mount} not mounted!"
notify "Backup : ${path_mount} not mounted!"
exit 1
2023-08-08 16:24:15 +03:00
fi
2023-12-11 16:56:09 +03:00
# Check if hot storage is mounted.
if [ ! -f "${path_src}"/.mount ]; then
echo "Backup : ${path_src} not mounted!"
notify "Backup : ${path_src} not mounted!"
exit 1
2023-08-08 16:24:15 +03:00
fi
2023-12-11 16:56:09 +03:00
# Tweak bash.
2023-08-08 16:24:15 +03:00
shopt -s globstar
shopt -s dotglob
2023-12-11 16:56:09 +03:00
# Cd to src storage.
builtin cd "${path_src}"
2023-08-08 16:24:15 +03:00
2023-12-11 16:56:09 +03:00
# Save media list.
/usr/bin/find ${path_media} -type d | gzip -1 > ${path_backup}/media/ColdMedia.txt.gz || notify 'Backup : Failed to save media list!'
2023-08-08 16:24:15 +03:00
2023-12-11 16:56:09 +03:00
# Backup docker.
rm ${path_docker}/${dow}_*.tgz
/usr/bin/tar --exclude-from=docker/.tarignore -c docker | /usr/bin/gzip -1 > ${path_docker}/docker.tgz && mv ${path_docker}/docker.tgz ${path_docker}/${dow}_${date}-$(/usr/bin/sha1sum ${path_docker}/docker.tgz | cut -d\ -f1).tgz || notify 'Backup : Failed to save docker!'
2023-08-08 16:24:15 +03:00
2023-12-30 16:18:02 +03:00
# Update checksums. NOTE: Now I manually archive all of that.
# builtin cd ${path_src}/media/book/ && recursive checksum_create || notify 'Backup : Checksum book failed!'
# builtin cd ${path_src}/media/music/ && recursive checksum_create || notify 'Backup : Checksum music failed!'
# builtin cd ${path_src}/media/paper/ && recursive checksum_create || notify 'Backup : Checksum paper failed!'
2023-12-30 16:18:02 +03:00
# Copy tmp media.
# /usr/bin/rsync -a --delete ${path_src}/media/book/ ${path_backup}/tmp/book/ || notify 'Backup : Failed to save books!'
# /usr/bin/rsync -a --delete ${path_src}/media/music/ ${path_backup}/tmp/music/ || notify 'Backup : Failed to save music!'
# /usr/bin/rsync -a --delete ${path_src}/media/paper/ ${path_backup}/tmp/paper/ || notify 'Backup : Failed to save paper!'
# /usr/bin/rsync -a --delete ${path_src}/media/porn/ ${path_backup}/tmp/porn/ || notify 'Backup : Failed to save porn!'
2023-12-11 16:56:09 +03:00
# Upload external.
2023-08-08 16:24:15 +03:00
#/usr/bin/rsync -ahP -e 'ssh -p 143 -i /var/roothome/document/key/ssh/pi.key' /var/mnt/backup/ root@192.168.1.6:/var/mnt/backup/ || notify 'backup : failed upload'
2023-12-11 16:56:09 +03:00
# Notify completion & size.
bupsize=$(/usr/bin/du -h ${path_docker}/${dow}_*.tgz | awk '{print $1}')
notify_silent "Backup : Complete ${bupsize}."
echo "Backup : Complete ${bupsize}."