#!/bin/bash #Variables: NET_HOME="/net/home/" TEACHERS_HOME="teachers" STUDENTS_HOME="students" OTHERS_HOME="others" MSG_NON_FOUND="File Not Found Exception" CONFIG="" DATA="" TEST="" TAR="star" usage(){ echo "USAGE" echo "lliurex-vault-homenets test {teachers|students|others}" echo "lliurex-vault-homenets backup {data|config} {teachers|students|others} DEST" echo "lliurex-vault-homenets restore SOURCE DEST" echo "lliurex-vault-homenets custom {backup|restore} SOURCE DEST" echo "lliurex-vault-homenets custom {test} SOURCE" } do_check_size_data(){ # Check the size of Net directories if [ -d $NET_HOME$1 ] ; then du -s $NET_HOME$1 | cut -d "/" -f1 else echo "$MSG_NON_FOUND $1" fi } backup_data_creation(){ # Create a Data Backup for $1 TAR_DIRECTORY=$(mktemp -d) for DIRECTORY in $(ls $NET_HOME$1); do echo "$TAR --exclude=".." --exclude="." -czvf $TAR_DIRECTORY/$1-$DIRECTORY.tgz $NET_HOME$1/$DIRECTORY/* >/dev/null 2>/dev/null" $TAR --exclude=".." --exclude="." -czvf $TAR_DIRECTORY/$1-$DIRECTORY.tgz $NET_HOME$1/$DIRECTORY/* >/dev/null 2>/dev/null done echo $TAR_DIRECTORY #rm -rf $TAR_DIRECTORY } backup_config_creation(){ # Create a Data Backup for $1 TAR_DIRECTORY=$(mktemp -d) for DIRECTORY in $(ls $NET_HOME$1); do $TAR --exclude=".." --exclude="." --exclude="*firefox*Cache*" -czvf $TAR_DIRECTORY/$1-$DIRECTORY.tgz $NET_HOME$1/$DIRECTORY/.* >/dev/null 2>/dev/null done echo $TAR_DIRECTORY #rm -rf $TAR_DIRECTORY } restore_backup_creation(){ # Restore Data Backup for $1 if [ -f "$1" -a -d "$2" ] ; then $TAR -xv $1 $2 exit 0 fi exit 1 } #MAIN ACTION="$1" shift case "$ACTION" in test) if [ -z "$1" ] ; then usage fi do_check_size_data $1 exit 0 ;; backup) if [ -z "$2" ] ; then usage fi if [ "$1" == "data" ] ; then backup_data_creation $2 fi if [ "$1" == "config" ]; then backup_config_creation $2 fi exit 0 ;; restore) if [ -z "$2"] ; then usage fi if [ -f "$1" ] ; then restore_backup_creation $1 $2 fi exit 0 ;; custom) CUSTOM_ACTION=$1 shift case "$CUSTOM_ACTION" in test) if [ -z "$1" ] ; then usage fi exit 0 ;; backup) usage ;; restore) usage ;; *) usage ;; esac ;; *) usage exit 1 ;; esac