Skip to content

Instantly share code, notes, and snippets.

@BobBurns
Created April 5, 2015 01:29
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 BobBurns/1801a185f3efd125b0df to your computer and use it in GitHub Desktop.
Save BobBurns/1801a185f3efd125b0df to your computer and use it in GitHub Desktop.
bash script to backup directory to usb drive
#
# important! cannot use this program to backup itself ->$HOME/bin
# script to backup directory to usb drive mounted to bobsUSB
#
# first make sure file is used as argument
if [ ! -d "$1" ]
then
echo "usage: better_backup mydir"
exit 1
fi
# first check if bobsUSB is mounted
if [ $(mount | grep -c /mnt/bobsUSB) != 1 ]
then
sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/bobsUSB || exit 1
echo "/mnt/bobsUSB is now mounted"
else
echo "/mnt/bobsUSB is already mounted"
fi
# make tarball of directory and move it to bobsUSB
now=$(date +"%m_%d_%Y")
# strip slashes
name=${1##/*/}
_file="$name$now.tar.gz"
echo "creating backup of $_file..."
tar -czvf $_file $1 || exit 1
mv $_file /mnt/bobsUSB || exit 1
echo "success!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment