Skip to content

Instantly share code, notes, and snippets.

@alicraigmile
Last active May 28, 2021 15:19
Show Gist options
  • Select an option

  • Save alicraigmile/acf73eaaf4e0c774854ff4d08f46842e to your computer and use it in GitHub Desktop.

Select an option

Save alicraigmile/acf73eaaf4e0c774854ff4d08f46842e to your computer and use it in GitHub Desktop.
lsbackup
#!/bin/bash
################################################################################
# Variables
################################################################################
# Credit variables
MY_NAME="lsbackup"
MY_DESC="How old are the backups held on this machine?"
MY_PROJ="https://gist.github.com/alicraigmile/acf73eaaf4e0c774854ff4d08f46842e"
MY_AUTH="alic"
MY_MAIL="[email protected]"
MY_VERS="1.0"
MY_DATE="2021-05-28"
# Default variables
# assumes folder structure $directory/$machine/$disk
directory='/content/Backups'
#debugging
#set -x
################################################################################
# Variables
################################################################################
print_usage() {
echo "$MY_NAME - $MY_DESC"
echo ""
echo "Usage: ${MY_NAME} [-h] <folder>"
}
_datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
echo $(( (d1 - d2) / 86400 )) days
}
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
age=$(( (d1 - d2) / 86400 ))
years=$(( age / 365 ))
days=$(( age % 365 ))
if [[ "$years" -eq "0" ]]
then
echo $days days
else
echo $years years, $days days
fi
#echo $(( (d1 - d2) / 86400 )) days
}
################################################################################
# The application
################################################################################
if [ "$#" -gt "0" ]; then
opts=$1
if [[ $1 -eq '-h' ]]; then
print_usage
exit
else
directory=$1
fi
fi
echo ""
echo "Backup folder: $directory"
echo ""
for machine in "$directory"/*
do
echo "[$(basename $machine)]"
for entry in "$machine"/*
do
if [[ -e "$entry/current" ]]
then
backupdate=$(basename $(readlink -f "$entry/current") | cut -d'_' -f1)
if [[ -z $backupdate ]]
then
estimaed='(extimated)'
backupdate=$(stat -c %y "$entry/current" | cut -d'.' -f1)
else
estimated=''
fi
else
estimated='(estimated)'
backupdate=$(stat -c %y "$entry" | cut -d'.' -f1)
fi
age=$(datediff 'today' "$backupdate")
disk=$(basename $entry)
printf '%.40s %s %s\n' "$disk$(printf '%.1s' .{1..40})" "$age" "$estimated"
done
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment