2023-08-08 16:24:15 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-11-28 02:15:24 +03:00
|
|
|
# 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
|
|
|
|
2023-11-03 21:04:44 +03:00
|
|
|
dow=$(/usr/bin/date +%u) # current day of week number.
|
|
|
|
date=$(/usr/bin/date +%Y%m%d%H%M) # date stamp.
|
2023-08-08 16:24:15 +03:00
|
|
|
path_src="/var/mnt/storage/hot" # backup src location.
|
|
|
|
path_media="/var/mnt/storage/cold_1/media /var/mnt/storage/cold_2/media" # media paths.
|
2023-12-11 16:56:09 +03:00
|
|
|
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.
|
|
|
|
|
|
|
|
# Check if backup drive is mounted.
|
|
|
|
if [ ! -f "${path_mount}"/.mount ]; then
|
|
|
|
echo "Backup : ${path_mount} not mounted!"
|
|
|
|
notify "Backup : ${path_mount} not mounted!"
|
2023-08-08 16:24:15 +03:00
|
|
|
exit 1
|
|
|
|
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!"
|
2023-08-08 16:24:15 +03:00
|
|
|
exit 1
|
|
|
|
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}/tmp/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-11-28 02:15:24 +03:00
|
|
|
# Update checksums.
|
2023-12-11 16:56:09 +03:00
|
|
|
cd ${path_src}/media/book/ && recursive checksum_create || notify 'Backup : Checksum book failed!'
|
|
|
|
cd ${path_src}/media/music/ && recursive checksum_create || notify 'Backup : Checksum music failed!'
|
|
|
|
cd ${path_src}/media/paper/ && recursive checksum_create || notify 'Backup : Checksum paper failed!'
|
|
|
|
|
|
|
|
# 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!'
|
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/cold_2/media/youtube/best/ ${path_backup}/tmp/youtube/ || notify 'Backup : Failed to save youtube!'
|
|
|
|
|
|
|
|
# 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}."
|