Making backup server go remote for searching what to backup?
Posted: 19 Jan 2011, 05:45
Hi all,
I have two Bubba2, one is main B2 and the second is backup B2.
I started with a rsync that is started by B2 main, and it works as expected. But I now want to change the direction so that the B2 backup server acts as described below. B2 backup server is doing all the backup logic, all a user on B2 main server has to do is to place a '.backupMe' file in his/her user folder.
I want to do the following:
* When B2 backup server boots up (either by a electronic timer or by manual start by power on button), it goes to B2 main server and scans thru all the user folders in /home for file '.backupMe'
* If file '.backupMe' is found in a user folder, B2 backup server rsyncs over from B2 main server the whole user folder and hard links the backup with a date
* When all home folders are scanned and none '.backupMe' is found, B2 backup server disconnects from B2 main server
* When B2 backup server is disconnected from B2 main server, B2 backup server turns off itself
I've had extended the initial backup script as found on http://forum.excito.net/viewtopic.php?f ... .txt#p9388, although it works, it is started on the main server and not on a backup server as I want.
More background details regarding the procedure:
The remote access is done by public key, so no password is used. The power off on B2 backup server works as well without any problem. The backup user is created on both servers and has read rights for the whole /home folder on B2 main server.
Now to my extended backup script for B2 backup server:
I've added the 'ssh main_server -l backup_user' in my backup script, but all it does is to log in into B2 main server and nothing more is happening.
Can somebody point out what I need to change to make it work?
Here's my code:
I have two Bubba2, one is main B2 and the second is backup B2.
I started with a rsync that is started by B2 main, and it works as expected. But I now want to change the direction so that the B2 backup server acts as described below. B2 backup server is doing all the backup logic, all a user on B2 main server has to do is to place a '.backupMe' file in his/her user folder.
I want to do the following:
* When B2 backup server boots up (either by a electronic timer or by manual start by power on button), it goes to B2 main server and scans thru all the user folders in /home for file '.backupMe'
* If file '.backupMe' is found in a user folder, B2 backup server rsyncs over from B2 main server the whole user folder and hard links the backup with a date
* When all home folders are scanned and none '.backupMe' is found, B2 backup server disconnects from B2 main server
* When B2 backup server is disconnected from B2 main server, B2 backup server turns off itself
I've had extended the initial backup script as found on http://forum.excito.net/viewtopic.php?f ... .txt#p9388, although it works, it is started on the main server and not on a backup server as I want.
More background details regarding the procedure:
The remote access is done by public key, so no password is used. The power off on B2 backup server works as well without any problem. The backup user is created on both servers and has read rights for the whole /home folder on B2 main server.
Now to my extended backup script for B2 backup server:
I've added the 'ssh main_server -l backup_user' in my backup script, but all it does is to log in into B2 main server and nothing more is happening.
Can somebody point out what I need to change to make it work?
Here's my code:
Code: Select all
#
# The original code is found in topic
# "Time Machine backup your Bubba users"
#
# http://forum.excito.net/viewtopic.php?f=8&t=2000&start=0
#
#!/bin/sh
# The ip address of the B2 main server to back up
BACKUP_HOST=<ip address>
# Log in as the following backup user
BACKUP_USER=backup_user
# Date stamp for backup folders on B2 backup server
date=`date "+%Y-%m-%dT%H:%M:%S"`
# File that should exist if we should do a backup
backupfile=".backupMe"
# Log in to B2 main server to be backed up
ssh $BACKUP_HOST -l $BACKUP_USER
# Where does the list of backups come from?
# Each user should keep a ".backupMe" file in their home root on B2 main server if they want their
# private folder to be backuped.
# 1. Create a list of users, that are found on B2 main server.
# 2. If that user has a backup.txt, backup the user.
users="`ls /home/`"
for user in $users;do
userhome="/home/$user/"
ignorefiles="/home/$user/.bas*"
dobackupfile="/home/$user/$backupfile"
if [ -f "$dobackupfile" ]; then
if [ -d $userhome ]; then
echo User: $user. Backup this user.
backuphome="/home/backup_user/$user"
currentbackup="$backuphome/current"
datebackuphome="$backuphome/$date"
echo $backuphome, $currentbackup, $userhome
BACKUPFOLDER="[ -d \"$backuphome\" ] || mkdir -p \"$backuphome\""
# If there doesn't exist a current backup on B2 backup server, create it.
if ssh $BACKUP_USER@$BACKUP_HOST $BACKUPFOLDER; then
echo backup folder Exists!
rsync -azP \
--link-dest=../current \
--exclude=$ignorefiles \
$userhome $BACKUP_USER@$BACKUP_HOST:/$backuphome/incomplete_back-$date \
&& ssh $BACKUP_USER@$BACKUP_HOST \
"mv $backuphome/incomplete_back-$date $backuphome/$date \
&& rm -f $backuphome/current \
&& ln -s $backuphome/$date $backuphome/current"
fi
else
echo No folder to backup, missing $userhome
fi
else
echo User: $user.
fi
done
# Exit ssh session from B2 main server
exit
# Turn myself off (B2 backup server)
sleep 2m
/home/backup_user/backupDestination/postBackup/powerOffMe.sh