Skip to content

Instantly share code, notes, and snippets.

@eladc
Created August 22, 2016 08:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eladc/16d45cb7cb3b6250ae56cb47f818a17d to your computer and use it in GitHub Desktop.
Save eladc/16d45cb7cb3b6250ae56cb47f818a17d to your computer and use it in GitHub Desktop.
System backup using tar
#!/bin/bash
## Checkfor valid parameters
if [ -z $1 ] ; then
echo "missing destination directory"
exit 1
else
if [ -d $1 ]; then
:
else
echo "directory does not exist"
exit 1
fi
:
fi
if [ -z $2 ]; then
echo "missing file name "
exit 1
else
:
fi
## File name and date
DATE=`date +%d-%m-%Y`
FILENAME=$2-$DATE.tar.gz
## Working directories
DESTDIR=$1
SRCDIR=/
echo $DESTDIR/$FILENAME
echo $DESTDIR | cut -c2-
## Make tarball of /
tar -cpzvf $DESTDIR/$FILENAME --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=tmp --exclude=$DESTDIR $SRCDIR >> $DESTDIR/$2.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment