Created
February 2, 2017 10:14
-
-
Save ninja-webdev/09304d4be8cba8499fda4dee3f2274a4 to your computer and use it in GitHub Desktop.
general backup script
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
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