Backup Web Project to Users Home folder www_backups
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 | |
if [ -z $1 ]; then | |
echo "please: Enter Web-Site Project folder name" | |
exit 1 | |
fi | |
WWW_FOLDER_PATH=/var/www/ | |
BACKUP_TO=~/www_backups | |
BACKUP_JOB_NAME=Backup_for_WWW_Project_ | |
DAYS_TO_KEEP=65 | |
mkdir -p $BACKUP_TO | |
# %F is Full Date same as %Y-%m-%d @ T for Time as in %H:%M:%S | |
DATE_STAMP=$(date +"%F@%T") | |
# Remove Root Folder if any, IG: frames/Example - will remove frames/ and Keep Example | |
PROJECT_FOLDER=${1##*/} | |
BACKUP_FILE_NAME=${BACKUP_JOB_NAME}${PROJECT_FOLDER}_$DATE_STAMP | |
TGZ=$BACKUP_FILE_NAME.tgz | |
# z for gzip, c is to create the archive, v to show verbose, f name of file, -C enter Directory. | |
tar --exclude .git --exclude vendor --exclude node_modules -zcvf "$BACKUP_TO/$TGZ" -C "$WWW_FOLDER_PATH" "$1" | |
RED="\033[31m" | |
RESET="\033[0m" | |
echo -e "\r\n $RED DEFAULT of $DAYS_TO_KEEP days worth of Backup Jobs to KEEP set. \r\n" | |
function remove_old_jobs() { | |
# Delete OLD Backups, so drive does not get filled up!! | |
echo "Removing OLD jobs..." | |
find $BACKUP_TO -name "${BACKUP_JOB_NAME}*.tgz" -mtime +$DAYS_TO_KEEP -delete | |
exit 0 | |
} | |
read -r -p "$(echo -e $RED'Would you like to DELETE your OLD Backups? IF so, say YES! : '$RESET)" Agree | |
case $Agree in | |
YES!|Yes!|yes!) remove_old_jobs;; | |
*) echo "OK...Keeping older Backups.";; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment