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.
|
|
|
|
path_mount="/var/mnt/backup" # 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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
fi
|
|
|
|
|
|
|
|
# tweak bash.
|
|
|
|
shopt -s globstar
|
|
|
|
shopt -s dotglob
|
|
|
|
|
|
|
|
# cd to src storage.
|
|
|
|
builtin cd "$path_src"
|
|
|
|
|
|
|
|
# save media list.
|
2023-11-19 10:16:17 +03:00
|
|
|
/usr/bin/find $path_media -type d | gzip -1 > ${path_backup}/tmp/ColdMedia.txt.gz || notify 'backup : save media list failed'
|
2023-08-08 16:24:15 +03:00
|
|
|
|
|
|
|
# backup docker.
|
2023-11-14 05:56:07 +03:00
|
|
|
rm $path_docker/${dow}_*.tgz
|
2023-11-14 05:58:09 +03:00
|
|
|
/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 : docker failed'
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-11-28 02:15:24 +03:00
|
|
|
# Update checksums.
|
2023-11-28 02:52:27 +03:00
|
|
|
cd /var/mnt/storage/hot/media/book/ && recursive checksum_create || notify 'Backup : checksum book failed.'
|
2023-12-05 13:02:54 +03:00
|
|
|
cd /var/mnt/storage/hot/media/music/ && recursive checksum_create || notify 'Backup : checksum music failed.'
|
|
|
|
cd /var/mnt/storage/hot/media/paper/ && recursive checksum_create || notify 'Backup : checksum paper failed.'
|
2023-11-28 02:15:24 +03:00
|
|
|
|
2023-08-08 16:24:15 +03:00
|
|
|
# copy media.
|
2023-11-28 02:15:24 +03:00
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/hot/media/book/ /var/mnt/backup/backup/tmp/book/ || notify 'backup : copy book failed'
|
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/hot/media/music/ /var/mnt/backup/backup/tmp/music/ || notify 'backup : copy music failed'
|
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/hot/media/paper/ /var/mnt/backup/backup/tmp/paper/ || notify 'backup : copy paper failed'
|
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/hot/media/porn/ /var/mnt/backup/backup/tmp/porn/ || notify 'backup : copy porn failed'
|
|
|
|
/usr/bin/rsync -a --delete /var/mnt/storage/cold_2/media/youtube/best/ /var/mnt/backup/backup/tmp/youtube/ || notify 'backup : copy youtube failed'
|
2023-08-08 16:24:15 +03:00
|
|
|
|
|
|
|
# upload external.
|
|
|
|
#/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'
|
|
|
|
|
|
|
|
# notify completion & size.
|
2023-11-14 05:58:09 +03:00
|
|
|
bupsize=$(/usr/bin/du -h $path_docker/${dow}_*.tgz | awk '{print $1}')
|
2023-08-08 16:24:15 +03:00
|
|
|
notify_silent "backup : complete : $bupsize"
|
|
|
|
echo "backup : complete : $bupsize"
|