Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create backup archive of Drupal project files
#!/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
You can’t perform that action at this time.