Backup : Rewrite.

This commit is contained in:
Dmitry Voronin 2024-01-03 20:56:18 +03:00
parent 32d06272e6
commit db16b4cb8d

View file

@ -1,28 +1,31 @@
#!/bin/bash #!/bin/bash
# Source modules.
for file in /var/roothome/.config/bash/module/*.sh; do for file in /var/roothome/.config/bash/module/*.sh; do
source "${file}" source "${file}"
done done
dow=$(/usr/bin/date +%u) # current day of week number. function report() {
date=$(/usr/bin/date +%Y%m%d%H%M) # date stamp. echo "${*}"
path_src="/var/mnt/storage/hot" # backup src location. notify "${*}"
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. # Define constants.
path_media="/var/mnt/storage/cold_1/media /var/mnt/storage/cold_2/media" # media paths. 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. # Check if backup drive is mounted.
if [ ! -f "${path_mount}"/.mount ]; then if [ ! -f "${path_mount}"/.mount ]; then
echo "Backup : ${path_mount} not mounted!" report "Backup : ${path_mount} not mounted!"
notify "Backup : ${path_mount} not mounted!"
exit 1 exit 1
fi fi
# Check if hot storage is mounted. # Check if hot storage is mounted.
if [ ! -f "${path_src}"/.mount ]; then if [ ! -f "${path_src}"/.mount ]; then
echo "Backup : ${path_src} not mounted!" report "Backup : ${path_src} not mounted!"
notify "Backup : ${path_src} not mounted!"
exit 1 exit 1
fi fi
@ -31,24 +34,35 @@ shopt -s globstar
shopt -s dotglob shopt -s dotglob
# Cd to src storage. # Cd to src storage.
builtin cd "${path_src}" cd "${path_src}"
# Save media list. # Save media list.
/usr/bin/find ${path_media} -type d > ${path_backup}/media/ColdMedia.txt || notify 'Backup : Failed to save media list!' find ${path_media} -type d > ${path_backup}/media/ColdMedia.txt || report "Backup : Failed to save media list!"
cd ${path_backup}/media/ cd ${path_backup}/media/
archive_fast ColdMedia.txt && rm ColdMedia.txt archive_fast ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!"
archive_prune ColdMedia 1
cd - cd -
# Backup docker. # Backup docker.
rm ${path_docker}/${dow}_*.tgz docker=$(archive_fast docker/)
archive_fast docker/ bupsize=$(du ${docker} | awk '{print $1}')
bupsize=$(/usr/bin/du -h Docker_* | awk '{print $1}') mv ${docker} ${path_docker}/ || report "Backup : Failed to save docker!"
mv Docker_* ${path_docker}/ || notify 'Backup : Failed to save docker!'
# Prune old Docker copies.
cd ${path_docker} cd ${path_docker}
archive_prune Docker 7 archive_prune Docker 7
cd - 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 writes.
sync sync