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

77 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
# Source modules.
for file in /var/roothome/.config/bash/module/*.sh; do
source "${file}"
done
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.
# Check if backup drive is mounted.
if [ ! -f "${path_mount}"/.mount ]; then
report "Backup : ${path_mount} not mounted!"
exit 1
fi
# Check if hot storage is mounted.
if [ ! -f "${path_src}"/.mount ]; then
report "Backup : ${path_src} not mounted!"
exit 1
fi
# Tweak bash.
shopt -s globstar
shopt -s dotglob
# Cd to src storage.
cd "${path_src}"
# Save media list.
find ${path_media} -type d > ${path_backup}/media/ColdMedia.txt || report "Backup : Failed to save media list!"
cd ${path_backup}/media/
archive_fast ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!"
cd -
# Backup docker.
docker=$(archive_fast docker/)
bupsize=$(du ${docker} | awk '{print $1}')
mv ${docker} ${path_docker}/ || report "Backup : Failed to save docker!"
# Prune old Docker copies.
cd ${path_docker}
archive_prune Docker 7
cd -
# Prune game saves.
cd "${path_backup}/media/save/"
archive_prune Save 1
cd -
# 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 -
# Sync writes.
sync
# Notify completion & size.
notify_silent "Backup : Complete ${bupsize}."
echo "Backup : Complete ${bupsize}."