Skip to content

Instantly share code, notes, and snippets.

@ninja-webdev
Created February 2, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninja-webdev/09304d4be8cba8499fda4dee3f2274a4 to your computer and use it in GitHub Desktop.
Save ninja-webdev/09304d4be8cba8499fda4dee3f2274a4 to your computer and use it in GitHub Desktop.
general backup script
BAK="/bkp"
GZIP="$(which gzip)"
NOW=$(date +"%d-%m-%y_%T_%Z")
[ ! -d "$BAK" ] && mkdir -p "$BAK"
FILE=$BAK/backup$NOW.tar
FOLDERTOBACKUP=/var/www/
echo "Tarring the folder $FOLDERTOBACKUP to $FILE Please wait ..."
tar -cpf $FILE $FOLDERTOBACKUP
if [ $? -eq 0 ]
then
echo "... Done!"
fi
echo "Deleting all backup files that are at least 2 days old"
# -type f makes sure only files are deleted
find /bkp/* -type f -mtime +2 -print0 | xargs -0 rm
if [ $? -eq 0 ]
then
echo "... Two day old files have been deleted!"
else
echo "... Howday, there seems to be no files found to delete, w00t!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment