
# - Manual backup of home folder - #

# - Shell Scripts - #
# https://help.ubuntu.com/lts/serverguide/backup-shellscripts.html

# - HowTo Format Date For Display or Use In a Shell Script - #
# http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/

# Home-Backup.sh

#!/bin/sh
####################################
#
# Home Backup to NFS mount script.
#      File location: /usr/local/bin/Home-Backup.sh
#
#        Create file: sudo gedit /usr/local/bin/Home-Backup.sh
#                     Copy & Paste this document content into the file you just created
# 
# Run backup process: bash Home-Backup.sh
#    Restore process: cd /
#                     sudo tar -xzvf /home/Recovery/HomeDirectory-Backup/User-is_derayo/host-is_derayo-Monday-September-14-2015_19:28:08.tgz
#                     sudo tar -xzvf /home/Recovery/HomeDirectory-Backup/User-"User"/"host"-"User"-"Specific date/time of file".tgz
#
####################################

# Clear screen
clear

# What to backup. 
#backup_files="/home /var/spool/mail /etc /root /boot /opt"
#

# This line to be modified depending of user ID
#myUser="is_derayo"
#myUser=$USER

# User's name
myUser=$(whoami)
backup_files="/home/$myUser"

# Where to backup to.
#dest="/mnt/backup"
#
dest="/home/Recovery/HomeDirectory-Backup/User-$myUser"

# Create directories.
sudo mkdir -p $dest

# Create archive filename.
month=$(date +%B)
day=$(date +%A)

#dt=`date '+%m/%d/%Y_%H:%M:%S'`
dt=$(date +%d-%Y_%H:%M:%S)

# Computer's name
hostname=$(hostname -s)
archive_file="$hostname-$myUser-$day-$month-$dt.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
sudo tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

