Skip to content

Instantly share code, notes, and snippets.

@gadflysu
Created July 21, 2019 14:14
Show Gist options
  • Save gadflysu/eb36762ef7b905152a85901264619333 to your computer and use it in GitHub Desktop.
Save gadflysu/eb36762ef7b905152a85901264619333 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Author: gadflysu
# Version: 0.1.4
LONG_DATE=`date +%Y%m%d` # This Command will read the date.
SHORT_DATE=`date +%y%m%d` # get the date (short format)
TIME=`date +%H%M` # get the time
SRC=.ehforwarderbot
SRC_DIR=$HOME # Source backup folder.
DES=efb-data-$SHORT_DATE-$TIME.tar.gz # The filename including the date.
DES_DIR=$HOME/backup # Destination of backup file.
# backup
if test -e $SRC_DIR/$SRC
then
if test ! -d $DES_DIR
then
echo "Destination does NOT exist. Creating directory..."
mkdir -p $DES_DIR
echo "The backup directory was created."
fi
# main operation
tar -czvpf $DES_DIR/$DES -C $SRC_DIR $SRC
else
echo "Source does NOT exist."
fi
# delete outdated backups
find $DES_DIR -type f -mtime +7 -exec rm -f {} \;
# show some info
if test -s $DES_DIR/$DES
then
echo "Backup was saved as \"$DES\"."
else
echo "Stopped."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment