Created
April 5, 2015 01:29
-
-
Save BobBurns/1801a185f3efd125b0df to your computer and use it in GitHub Desktop.
bash script to backup directory to usb drive
This file contains 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
# | |
# 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