bashup/bashup-list-backups.sh
Matthew Saunders Brown 2b232c41f9 initial uploads
2021-01-21 13:58:30 -08:00

47 lines
1.2 KiB
Bash

#!/bin/bash
#
# Bashup - A set of bash scripts for managing backups.
# https://git.stack-source.com/msb/bashup
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# backups are stored here
backup_storage_dir='/mnt/backups';
# check for local config, which can be used to override any of the above
if [[ -f /usr/local/etc/bashup.cnf ]]; then
source /usr/local/etc/bashup.cnf
fi
if [ ! -d $backup_storage_dir ]; then
echo "ERROR: Backup storage dir ($backup_storage_dir) does not exist."
exit 1
fi
# check if backup_storage_dir is a mount in fstab
grep -qs " $backup_storage_dir " /etc/fstab
if [ $? -eq 0 ]; then
# check if backup_storage_dir is already mounted
grep -qs " $backup_storage_dir " /proc/mounts
if [ $? -ne 0 ]; then
# attempt to mount backups
mount $backup_storage_dir
# re-check for backups mount
grep -qs " $backup_storage_dir " /proc/mounts
if [ $? -ne 0 ]; then
echo "ERROR: failed to mount $backup_storage_dir"
exit 1
fi
fi
fi
# output list of backups (dates)
ls -1 $backup_storage_dir | grep -v lost+found
# check if backup_storage_dir is mounted and unmount if so
grep -qs " $backup_storage_dir " /proc/mounts
if [ $? -eq 0 ]; then
umount $backup_storage_dir
fi
exit 0