client=host1
server=server1
user=backupuser
userpw=backupuserpw
Create “backupuser†and assign “backuppuserpw†on both host1 and server1.
useradd backupuser
passwd backupuser
enter backupuserpw twice
Generating your private/public key pair
To be able to logon to another server without being prompted for your
password, you need to generate a key that will be trusted by server1,
where your backups will be sent to. To accomplish this, follow the
following steps as the user you will use (backupuser here).
On host1:
ssh-keygen -t rsa
You will then be prompted for a file name. Leave it as the default by simply pressing “Enterâ€Â.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/backupuser/.ssh/id_rsa):
The
last step of the key creation is the passphrase. Since the purpose of
this is to not enter a password, hence being able to create batch jobs,
just hit “Enter†twice, leaving them blank.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/backupuser/.ssh/id_rsa.
Your public key has been saved in /home/backupuser/.ssh/id_rsa.pub.
The key fingerprint is:
a6:84:5d:a6:cd:ff:31:48:21:85:ca:46:93:88:7a:50 backupuser@host1
This just created 2 files in backupuser’s home directory. ~/.ssh/id_rsa (the private key) and ~/.ssh/id_rsa.pub.
The
id_rsa.pub is your public key, which you share with server1. The id_rsa
is your private key, and this is only for you. Do not lose it or share
it with anyone, as this is your passkey! Make sure the file is not
readable by anyone but you (chmod 600 ~/.ssh/id_rsa). Anyone having a
copy of this key could usurpate your identity and login to this server
as you. It is not any more dangerous to use this method as to use a
traditional password, but I will not enter into a debate here.
Now that you have your keyring, it is time to send your public key to server1, so that it can trust you.
Sharing your host1 public key
First things first, let’s make sure that the remote folder into which
you will put this key exists (~/.ssh), and will only be readable by
backupuser.
ssh server1 “mkdir .ssh; chmod 600 .sshâ€Â
This
time, it will prompt you for your password. Enter it. If the remote
directory didn’t exist, everything should go without a hitch. If not
you will receive a message like mkdir: cannot create directory `.ssh’:
File exists., which is fine. The permissions will be changed
nevertheless.
Next step is to actually copy your public key in the remote directory, like this:
scp ~/.ssh/id_rsa.pub server1:.ssh/authorized_keys
backupuser@host1:~$ scp ~/.ssh/id_rsa.pub server1:.ssh/authorized_keys
backupuser@server1’s password:
id_rsa.pub 100% 225 0.0KB/s 00:00
backupuser@host1:~$
You should now be able to ssh server1, and not being prompted for a password.
Create a directory on server1:
ssh server1 “mkdir backupsâ€Â
Install unixbu:
unzip unixbu-0.07.tar.gz
cd unixbu
type ./configure
vi etc/unix.common and change varibles to match…
#######################################################################################
#/bin/bash
##################################################
# David Ames
# unix.common v 0.05
# 06/08/2004
# unix.common contains common variables and
# functions for unixbu and unixscp
#
##################################################
##################################################
# Common Variables
# Set these for each environment
#
PREFIX=/usr/local
# List of directories to be backed up
DIRS=†/etc \
/home/jengstro \
/var/www/html \
â€Â
LOG=/var/log/backup.log
ERRLOG=/var/log/backup.err.log
HOST=`CHANGEME`
# This is the location the tar files
# will reside on the local system
TMP=/home/backupuser
EMAIL=que@wanderinghorde.com
SCP=/usr/bin/scp
GZIP=/bin/gzip
TAR=/bin/tar
FIND=/usr/bin/find
XARGS=/usr/bin/xargs
USER=backupuser
SID=/home/$USER/.ssh/id_dsa
DSTHOST=CHANGEME
DSTDIR=â€Â/backupsâ€Â
# Numeric day of week is also the number of days
# prior to today that needs to be backed up in a
# diff backup
# *** This assumes full backups occur on Sunday. ****
# Monday is 1
# Sunday is 7
NUMDAY=`date +%u`
DAY=`date +%a`
FULLTAR=$TMP/${HOST}.weekly.full.${DAY}.tar
DIFFTAR=$TMP/${HOST}.daily.diff.${DAY}.tar
# Mysql Setup
#
MYSQLBU=true
DBUSER=root
DBPASS=CHANGEME
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
MYSQLADMIN=/usr/bin/mysqladmin
MYSQLTAR=$TMP/${HOST}.mysql.${DAY}.tar
# Check for the correct amount of arguments
if [ $# -lt 1 ] || [ $# -gt 1 ]
then
echo “Please choose ‘full’ or ‘diff’ backup.â€Â
echo “Usage: `basename $0` â€Â
exit 1
fi
# Read in argument
case $1 in
full) TYPE=full
;;
diff) TYPE=diff
;;
*) echo “Please choose ‘full’ or ‘diff’ backup.â€Â
echo “Usage: `basename $0` â€Â
exit 1 ;;
esac
##################################################
# Common Functions
#
# Function errrorReport takes in
# two arguments: ReturnValue and Command string
function errorReport() {
echo “$HOST backup had an error doing:
$2.
The return value was $1.
See $HOST:$LOG and $HOST:$ERRLOG for more detail.†| mail -s “$HOST Backup Warning†$EMAIL
}
#EOF
#######################################################################################
Then execute ./install
As backupuser execute crontab -e and enter the following:
30 4 1 * * /usr/local/sbin/startunixbu full
30 4 * * 1 /usr/local/sbin/startunixbu diff