Last active
August 29, 2015 14:17
-
-
Save fcayci/4a1cc12b84170fed59ab to your computer and use it in GitHub Desktop.
tar back-up the directory and save it in NFS share
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
#!/bin/bash | |
# Furkan Cayci | |
# tar back-up the directory and save it in NFS share | |
VERSION="v0.2" | |
SERVERADDR=10.0.0.1 | |
BACKUPDIR=/tank/backup | |
MOUNT="/export" | |
NOW="$(date +'%F-%H-%M')" | |
BASEDIR="${PWD##*/}" | |
BACKUPNAME=${HOSTNAME}${VERSION}_${BASEDIR}_${NOW}.tar | |
echo -e "Current date is: \033[1;32m$NOW\t\033[0;37m Backup directory is: \033[1;32m$BASEDIR\033[0;37m" | |
if grep -qs "$MOUNT" /proc/mounts; then | |
echo -e "[I] NFS share 'backup' is mounted as /export" | |
else | |
sudo /bin/mount -t nfs ${SERVERADDR}:${BACKUPDIR} ${MOUNT} -o vers=3 | |
if [ $? -eq 0 ]; then | |
echo -e "[I] NFS share 'backup' is mounted as /export" | |
else | |
echo -e "\033[1;31m[E] Cannot mount backup share. Check if VPN is connected, or mount manually. Exitting...\033[0;37m" | |
exit -1 | |
fi | |
fi | |
echo -e "[I] Backing up \033[1;32m$PWD\033[0;37m directory as \033[1;32m$BACKUPNAME\033[0;37m" | |
read -p "[Q] Confirm [y/n] : " -n 1 answer | |
if [ "$answer" == "y" ]; then | |
/bin/tar cf /export/${BACKUPNAME} . | |
echo -e "\n[I] Done..." | |
echo -e "[I] ${PWD} directory backup is at \033[1;34m${SERVERADDR}:/export/${BACKUPNAME}\033[0;37m" | |
else | |
echo -e "\n\033[1;31m[W] Exiting without backing up...\033[0;37m" | |
exit -2 | |
fi | |
#sudo umount /export |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment