2023-08-08 16:24:15 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-03 20:56:18 +03:00
|
|
|
# Source modules.
|
2024-01-03 18:39:38 +03:00
|
|
|
for file in /var/roothome/.config/bash/module/*.sh; do
|
|
|
|
source "${file}"
|
|
|
|
done
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2024-01-03 20:56:18 +03:00
|
|
|
function report() {
|
|
|
|
echo "${*}"
|
|
|
|
notify "${*}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Define constants.
|
|
|
|
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.
|
|
|
|
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
|
2024-01-03 20:56:18 +03:00
|
|
|
report "Backup : ${path_mount} not mounted!"
|
2023-12-30 13:34:00 +03:00
|
|
|
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
|
2024-01-03 20:56:18 +03:00
|
|
|
report "Backup : ${path_src} not mounted!"
|
2023-12-30 13:34:00 +03:00
|
|
|
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.
|
2024-01-03 20:56:18 +03:00
|
|
|
cd "${path_src}"
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-11 16:56:09 +03:00
|
|
|
# Save media list.
|
2024-01-03 20:56:18 +03:00
|
|
|
find ${path_media} -type d > ${path_backup}/media/ColdMedia.txt || report "Backup : Failed to save media list!"
|
2024-01-03 18:39:38 +03:00
|
|
|
cd ${path_backup}/media/
|
2024-01-03 20:56:18 +03:00
|
|
|
archive_fast ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!"
|
2024-01-03 18:39:38 +03:00
|
|
|
cd -
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2023-12-11 16:56:09 +03:00
|
|
|
# Backup docker.
|
2024-01-03 20:56:18 +03:00
|
|
|
docker=$(archive_fast docker/)
|
|
|
|
bupsize=$(du ${docker} | awk '{print $1}')
|
|
|
|
mv ${docker} ${path_docker}/ || report "Backup : Failed to save docker!"
|
|
|
|
|
|
|
|
# Prune old Docker copies.
|
2024-01-03 18:39:38 +03:00
|
|
|
cd ${path_docker}
|
|
|
|
archive_prune Docker 7
|
|
|
|
cd -
|
2023-08-08 16:24:15 +03:00
|
|
|
|
2024-01-11 21:16:06 +03:00
|
|
|
# Prune game saves.
|
|
|
|
cd "${path_backup}/media/save/"
|
|
|
|
archive_prune Save 1
|
|
|
|
cd -
|
|
|
|
|
2024-01-03 20:56:18 +03:00
|
|
|
# Backup some media.
|
|
|
|
cd ${path_src}/media/
|
|
|
|
paper=$(archive_fast paper/)
|
|
|
|
mv ${paper} ${path_backup}/media/ || report "Backup : Failed to save paper!"
|
|
|
|
cd -
|
|
|
|
|
|
|
|
# Prune media copies.
|
|
|
|
cd ${path_backup}/media/
|
|
|
|
archive_prune
|
|
|
|
cd -
|
|
|
|
|
2024-01-03 18:43:18 +03:00
|
|
|
# Sync writes.
|
|
|
|
sync
|
|
|
|
|
2023-12-11 16:56:09 +03:00
|
|
|
# Notify completion & size.
|
|
|
|
notify_silent "Backup : Complete ${bupsize}."
|
|
|
|
echo "Backup : Complete ${bupsize}."
|