Last active
April 8, 2016 16:17
-
-
Save cluke009/6446e630f7ac18f787760d3251cdaa81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# https://nicaw.wordpress.com/2013/04/18/bash-backup-rotation-script/ | |
# Julius Zaromskis | |
# Backup rotation | |
# Storage folder where to move backup files | |
# Must contain backup.monthly backup.weekly backup.daily folders | |
# Source folder where files are backed | |
source=$1/incoming | |
drush ard --destination=$source/archive.tgz | |
# Destination file names | |
date_daily=`date +"%d-%m-%Y"` | |
# Get current month and week day number | |
month_day=`date +"%d"` | |
week_day=`date +"%u"` | |
# Optional check if source files exist. Email if failed. | |
if [ ! -f $source/archive.tgz ]; then | |
ls -l $source/ | mail [email protected] -s "[backup script] Daily backup failed! Please check for missing files." | |
fi | |
# It is logical to run this script daily. We take files from source folder and move them to | |
# appropriate destination folder | |
# On first month day do | |
if [ "$month_day" -eq 1 ] ; then | |
destination=backup.monthly/$date_daily | |
else | |
# On saturdays do | |
if [ "$week_day" -eq 6 ] ; then | |
destination=backup.weekly/$date_daily | |
else | |
# On any regular day do | |
destination=backup.daily/$date_daily | |
fi | |
fi | |
# Move the files | |
mkdir $destination | |
mv -v $source/* $destination | |
# daily - keep for 14 days | |
find $1/backup.daily/ -maxdepth 1 -mtime +14 -type d -exec rm -rv {} \; | |
# weekly - keep for 60 days | |
find $1/backup.weekly/ -maxdepth 1 -mtime +60 -type d -exec rm -rv {} \; | |
# monthly - keep for 300 days | |
find $1/backup.monthly/ -maxdepth 1 -mtime +300 -type d -exec rm -rv {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment