Skip to content

Instantly share code, notes, and snippets.

@samdoran
Created April 9, 2013 14:25
Show Gist options
  • Save samdoran/5346072 to your computer and use it in GitHub Desktop.
Save samdoran/5346072 to your computer and use it in GitHub Desktop.
Make empty month folders for testing snapshot cleanup.
#!/bin/bash
#
# Make empty month folders for testing backup cleanup
# --- Variables --- #
OS=$(uname -s)
HOST=$(hostname)
DESTINATION="./Backup/$HOST"
YEAR="$1"
TIME="$2"
# --- Main Program --- #
# Use current year if none was provided
if [[ $YEAR == '' ]]; then
YEAR=$(date +%Y)
fi
# Set a default timestamp if none was provided
if [[ $TIME == '' ]]; then
TIME=$(date +%H%M%S)
fi
# BSD date in OS X has a different syntax than GNU date in Linux
if [[ $OS == "Darwin" ]]; then
# Julian date used to ensure a folder for each day of that particular year is created
DAYS_IN_YEAR=$(date -j -f "%Y-%m-%d" "$YEAR-12-31" "+%j")
for (( d = 0 ; d < $DAYS_IN_YEAR ; d += 1)); do
mkdir -p $DESTINATION/$(date -v +${d}d -j -f "%Y-%m-%d" "$YEAR-1-1" "+%Y-%m-%d-$TIME")
done
elif [[ $OS == "Linux" ]]; then
DAYS_IN_YEAR=$(date -d "$YEAR-12-31" "+%j")
for (( d = 0 ; d < $DAYS_IN_YEAR ; d += 1)); do
mkdir -p $DESTINATION/$(date -d "$YEAR-1-1 + $d day" "+%Y-%m-%d-$TIME")
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment