Created
October 7, 2020 15:24
-
-
Save pathartl/457cb325601ec88e807f5ae9b770f7d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
Source=/apps | |
Destination=/data/Files/Backups/home.pathar.tl | |
DestinationFilename="$(date '+%Y-%m-%d.%H-%m').tar.gz" | |
mkdir -p "${Destination}/Daily" | |
mkdir -p "${Destination}/Weekly" | |
mkdir -p "${Destination}/Monthly" | |
# Get the current month and weekday integer | |
MonthDay=`date +"%d"` | |
WeekDay=`date +"%u"` | |
tar -zcf "${Destination}/Daily/$(date '+%Y-%m-%d.%H-%m').tar.gz" ${Source} | |
# If it's Sunday | |
if [ "$WeekDay" -eq 7 ] ; then | |
cd $Destination/Daily | |
# Remove all but the latest 8 dailies | |
ls -t $Destination/Daily | sort -r | tail -n +9 | xargs rm -- | |
# Move the oldest daily over into weekly | |
ls -t $Destination/Daily | sort -r | tail -n 1 | xargs -I {} mv {} $Destination/Weekly | |
fi | |
# If it's the first of the month | |
if [ "$MonthDay" -eq 1 ] ; then | |
cd $Destination/Weekly | |
# Move the oldest weekly over into monthly | |
ls -t $Destination/Weekly | sort -r | tail -n 1 | xargs -I {} mv {} $Destination/Monthly | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment