Skip to content

Instantly share code, notes, and snippets.

@Deele
Last active August 21, 2019 13:31
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 Deele/0198c16beb35b9bf44a81b60ae68eeac to your computer and use it in GitHub Desktop.
Save Deele/0198c16beb35b9bf44a81b60ae68eeac to your computer and use it in GitHub Desktop.
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