#!/bin/sh

# you need to generate your public/private ssh keys to use this script.
# this can be done with `ssh-keygen -t dsa' 
# then, on the other-side box, put your private key to 
# $HOME/.ssh/authorized_keys
#
# to repeat this script every seven days at 20:15, put to root's crontab:
# 15  20  */7  *  *  /root/scripts/backup.sh 2>&1 > /dev/null
#
# - Daniel Gerzo

# date format for file-name of backup
date="`date "+%Y-%m-%d"`"

# file-name which the backup save to
name="/var/backups/data.backup-${date}.tar.gz"

# database dump
#/usr/local/bin/mysqldump -A -pPASS > /var/backups/sqlbackup.sql

# what to backup
backup='/etc /usr/local/etc /root /var/named/etc/namedb'

# host of the box where the backup store to
host='user@host.domain.tld'

# directory of the remote box for backups
dir='backups/'

tar -czpP -f ${name} ${backup}
chmod 600 ${name}
scp ${name} ${host}:${dir}
rm -f ${name} #/var/backups/sqlbackup.sql

exit 0
