Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A script to backup chosen folders to an offline USB hard disk drive.
#! /bin/bash
# Code by Bharath Bhushan Lohray
# https://bharath.lohray.com/
# github: lordloh
# bitbucket: lordloh
PART_ID="926fc38e-bc7e-467a-953e-25c6555939a0"
now=$(date)
echo "===== Running at $now ====="
if [ -b /dev/disk/by-uuid/"$PART_ID" ]; then
echo "Partition Found!"
mkdir ~/$PART_ID
mount $PART_ID
if [ $? -eq 0 ]; then
echo "Mounted"
# Run backups
rsync -r "/home/bharath/hubic/Datasheets" ~/$PART_ID/.
rsync -r "/home/bharath/hubic/Harvard Business Review" ~/$PART_ID/.
rsync -r "/home/bharath/hubic/IEEE Computer Magazine" ~/$PART_ID/.
rsync -r "/home/bharath/hubic/Linux Journal" ~/$PART_ID/.
rsync -r "/home/bharath/hubic/MagPi" ~/$PART_ID/.
rsync -r "/home/bharath/hubic/Make Magazine" ~/$PART_ID/.
rsync -r "/home/bharath/Photos" ~/$PART_ID/.
rsync -rl "/home/bharath/Datasets" ~/$PART_ID/.
sync
df --output=size,used,avail,pcent -h $PART_ID
free_space=$(df --output=avail -h $PART_ID)
umount $PART_ID
pushb "Vault backup done.[$free_space]"
if [ $? -eq 0 ]; then
echo "Unmounted"
rm -Rf ~/$PART_ID
now=$(date)
echo "===== Done at $now ====="
fi
fi
else
echo ":-("
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment