Last active
August 21, 2019 13:31
-
-
Save Deele/0198c16beb35b9bf44a81b60ae68eeac to your computer and use it in GitHub Desktop.
Create backup archive of Drupal project files
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 | |
# | |
# Settings | |
# | |
DIRECTORY="drupal-project" | |
# | |
# Begin | |
# | |
START_TIME=$SECONDS | |
# | |
# Create file name | |
# | |
NOW=$(date +"%m%d%Y-%H%M%S") | |
function create_file_name() { | |
FILE="backup__" | |
FILE+=$1 | |
FILE+="__" | |
FILE+=$2 | |
FILE+="-" | |
FILE+=$3 | |
FILE+=".tar.gz" | |
} | |
COUNTER=1 | |
create_file_name $DIRECTORY $NOW $COUNTER | |
while [[ -f "$FILE" ]]; do | |
((COUNTER++)) | |
create_file_name $DIRECTORY $NOW $COUNTER | |
done | |
# | |
# Directory size | |
# | |
echo "Calculating size of $DIRECTORY..." | |
DIRSIZE="`du -hs $DIRECTORY`" | |
DIRSIZE=${DIRSIZE%G*} | |
echo "Its $DIRSIZE GB, starting backup to $FILE..." | |
# | |
# Create archive | |
# | |
tar -czf $FILE $DIRECTORY --exclude=$DIRECTORY/.git --exclude=$DIRECTORY/web/sites/default/files/php --exclude=$DIRECTORY/web/sites/default/files/styles --exclude=$DIRECTORY/web/sites/default/files/js | |
# | |
# Information | |
# | |
ELAPSED_TIME=$(($SECONDS - $START_TIME)) | |
FILESIZE="`du -hs $FILE`" | |
FILESIZE=${FILESIZE%G*} | |
echo "Done. Archive size is $FILESIZE GB, elapsed time: $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment