BACKUP_FILES="/etc /root /home /var /srv /opt"
DEST="/backup"
FILENAME="backup-hostname"
DAY=$(date +%A)
SCPUSER=scpbackup
SCPHOST="somehost.domain.com"
SCPPORT=""
SSHKEY="-i/root/backup/id_rsa.file"
 
# Find which week of the MONTH 1-4 it is.
DAY_NUM=$(date +%_d)
if (( $DAY_NUM <= 7 )); then
        WEEK_FILE="$FILENAME-week1.tgz"
elif (( $DAY_NUM > 7 && $DAY_NUM <= 14 )); then
        WEEK_FILE="$FILENAME-week2.tgz"
elif (( $DAY_NUM > 14 && $DAY_NUM <= 21 )); then
        WEEK_FILE="$FILENAME-week3.tgz"
elif (( $DAY_NUM > 21 && $DAY_NUM < 32 )); then
        WEEK_FILE="$FILENAME-week4.tgz"
fi
 
# Find if the Month is odd or even.
MONTH_NUM=$(date +%m)
MONTH=$(expr $MONTH_NUM % 2)
if [ $MONTH -eq 0 ]; then
        MONTH_FILE="$FILENAME-month2.tgz"
else
        MONTH_FILE="$FILENAME-month1.tgz"
fi
 
# Create archive filename.
if [ $DAY_NUM -eq 1 ]; then
	ARCHIVE_FILE=$MONTH_FILE
elif [ $DAY != "Saturday" ]; then
        ARCHIVE_FILE="$FILENAME-$DAY.tgz"
else 
	ARCHIVE_FILE=$WEEK_FILE
fi
 
# Print start status message.
echo "`date`: Backing up $BACKUP_FILES to $DEST/$ARCHIVE_FILE"
 
# Backup the files using tar.
tar -czf $DEST/$ARCHIVE_FILE $BACKUP_FILES
 
# Print end status message.
echo "`date`: Backup finished"
 
# SCP the file
scp $SSHKEY $SCPPORT $DEST/$ARCHIVE_FILE $SCPUSER@$SCPHOST:/some/path/

# Delete the file
rm $DEST/$ARCHIVE_FILE
 
# Done
echo "`date`: SCP done."
