Also scp works passwordless and secure.
First create transfer user at central server and give necceseery permissions.
At the main server:
# useradd transfer -d /export/home/transfer
# passwd transfer
# chown transfer /centralbackup/dir
At servers which you are going to backup, create public keys.
# ssh-keygen -t rsa
# cat ~/.ssh/id_rsa.pub
copy content to the transfer user in central server /transferuserhomedirectory/.ssh/authorized_keys . Be carefull there is no line break in the id_rsa.pub file.
now you can login without password to central server test is ssh transfer@centralserver.
This is the script that you can backup weekly.
backupname=$(hostname)_$(date '+%Y%m%d')
backupdir=/site/local/backupdir
remotebackupdir=/centralbackup/dir
remoteloc=transfer@mainserver:$remotebackupdir
mailaddress="yourmailaddress@domaim.com"
#if you want to exclude directories when you are creating flash archive use -x
flarcreate -c -S -n $backupname -x /putdirthatyouwanttoexclude -x /anotherexclude $backupdir/$backupname.flar
#check if there is problem creating flash archive
if [ $? -ne 0 ] ; then
echo flarcreate problem in $(hostname) "\n" | mailx -s "$(hostname) flarcreate problem" $mailaddress
exit 1
fi
scp $backupdir/$backupname.flar $remoteloc
#check if there is problem copying to central server.
if [ $? -ne 0 ] ; then
echo backup copy problem in $(hostname) "\n" | mailx -s "$(hostname) backup copy problem" $mailaddress
exit 1
fi
#deletes backup of previous week
rm $backdir/$(hostname)_$(TZ=GMT+167 date +%Y%m%d).flar
#check if there is problem deleting file
if [ $? -ne 0 ] ; then
echo old backup delete problem in $(hostname) "\n" | mailx -s "$(hostname) old backup delete problem" $mailaddress
exit 1
fi
1 comment:
ellerin dert gormesin. Ugur.
Post a Comment