#!/bin/sh

# Auto-Backup Script Version 1.3.
# Created by ek <ek@thekeyboardcowboys.org>
# (http://www.thekeyboardcowboys.org/).

# This script is designed to create a backup of your
# home directory inside your home directory then upload
# the backup to an FTP server on another machine. Just
# change the defaults below and it should work.
#
# Also, don't forget to add a cron job to take care of 
# the automatic running of this script. Something along 
# the lines of:
# 55 1 * * * /path/to/home_backup.sh > /dev/null
# should work just fine. So, feel free to edit it however 
# you'd like if you're comfortable with coding. That being 
# said...
#          !!!USE AT YOUR OWN RISK!!!

####### EDIT THESE VARIABLES ################

# FTP server to connect to.
ftpserver="ftp.domain.tld"

# FTP username for backup upload.
ftpuser="backup_user"

# FTP password for backup upload.
ftppass="backup_user_password"

# FTP directory to upload to.
directory="/"

# Name to prepend backup file. (eg. backup-09-11.2004.tar.gz)
filename="backup"

##### DO NOT EDIT ANYTHING UNDER THIS LINE ################

date=`date +%m-%d-%Y`
cd $HOME/../
tar -cvzf $HOME/${filename}-${date}.tar.gz --exclude=$HOME/${filename}-${date}.tar.gz $HOME/
cd $HOME
ftp -in ${ftpserver} <<END_FTP
user ${ftpuser} ${ftppass}
cd ${directory}
binary
mdelete ${filename}-*.tar.gz
put ${filename}-${date}.tar.gz
quit
END_FTP
rm -rf $HOME/${filename}-${date}.tar.gz
exit 0

