Skip to content

Instantly share code, notes, and snippets.

@philiph
Created September 11, 2014 07:39
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 philiph/a48f3e79e3eb8190855c to your computer and use it in GitHub Desktop.
Save philiph/a48f3e79e3eb8190855c to your computer and use it in GitHub Desktop.
Bash script to backup a web front-end project to a timestamped .tar.gz archive.
#!/bin/bash
if [ $# -eq 0 ]; then
echo Expected: 1 arg which is the directory to backup.
exit 1
fi
project=$1
if [ ! -d "$project" ]; then
echo Directory not found: $project
exit 2
fi
timestamp=$(date +"%Y%m%d-%H%M%S")
filename=$project-$timestamp.tar.gz
echo Creating archive: $filename
tar --exclude='node_modules' --exclude='bower_components' --exclude="build" -czf $filename $project
file_size=`du -h "$filename" | cut -f1`
echo Archive file size is $file_size.
echo Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment