Automated backup of Linux Server to Windows


This tutorial assumes two things:
1) You are sharing a connection via a router or hub. One computer is linux, one is windows.

2) You have samba installed

First, you want to make the linux server be accessable by the windows machine. To do this, edit your smb.conf like so:

....
workgroup = WORKGROUP
....
#Whatever the windows machine static IP is, on the LAN
hosts allow = 192.168.2.100
....
#This is the share you want to map in windows
#in case you ever need to back up windows files to linux
[backup]
comment = Backup
path = /backup
browseable = yes
public = yes
writable = yes
create mask = 0770
directory mask = 0770


[etc]
comment = Etc
path = /etc
browseable = yes
public = yes
writable = yes
create mask = 0770
directory mask = 0770


#assuming you have a soft link to your htdocs in /root, you won't need
#to make another entry for apache's htdocs folder
[root]
comment = root
path = /root
browseable = yes
public = yes
writable = yes
create mask = 0770
directory mask = 0770
.....



Next, you're going to want to make sure each computer can access each other hassle free.
To do this, make an account called 'Guest' on both windows and linux. No password. In /etc/passwd change /bin/bash to /bin/false (or if bin/bash isn't there, add /bin/false at the end line of Guest anyways).

Next, usermod -G root Guest && usermod -G www-data Guest (www-data might be nobody if you use apache2). Now chmod -R 770 /root /etc /var/www (or path to htdocs).

An easier way to do this is a cron task.
crontab -e
* 0 * * * /root/chown-users >> /dev/null 2>&1

In /root/chown-users:
#!/bin/bash
for x in `ls /home`
do
chown -R $x /home/$x
chgrp -R users /home
chmod -R 705 /home
chmod 715 /home
done
chown -R Guest /backup
chmod 700 /backup
chgrp -R root /etc /root /usr/local/apache2/htdocs
chown -R 770 /etc /root /usr/local/apache2/htdocs


In Windows, make sure the Guest account is turned on, and has no password set to it.

Now type 'smbpasswd -a Guest'

When promted for a password, press enter.

Now make a 'Backup.bat' with the following code:


:::::::::::::::::::::::::::::::::::::::
::::::: Created by Will Twomey ::::::
::::::: 3:43 PM 6/25/2004 ::::::::::
:::::::::::::::::::::::::::::::::::::::
ECHO.
@ECHO OFF
CLS
ECHO.
ECHO ESTABLISHING NETWORK CONNECTION.......PLEASE WAIT
rem if "%1()"=="()" goto default
rem choice /c:y /t:y,3 /n
rem goto end
rem :default
rem choice /c:y /t:y,3 /n
rem :end
ECHO NETWORK CONNECTION ESTABLISHED........PLEASE WAIT
ECHO.
rem if "%1()"=="()" goto default1
rem choice /c:y /t:y,1 /n
rem goto end1
rem :default1
rem choice /c:y /t:y,4 /n
:end1
ECHO.
ECHO.
CLS
ECHO.
ECHO CLEANING CURRENT DIRECTORIES...
ECHO.
rem choice /c:y /t:y,4 /n
DEL /f /s /q F:\Backup\serverbackup\*.* >nul
echo.
cls
ECHO.
ECHO COPYING FILES.....PLEASE WAIT
ECHO.
ECHO ********************************************************
rem choice /c:y /t:y,4 /n
ECHO.
ECHO Copying /etc from Server2...please wait
echo.
XCOPY \\Server2\etc /S F:\Backup\serverbackup\Server2\etc
ECHO.
ECHO /etc successfully transfered
ECHO.
rem choice /c:y /t:y,4 /n
CLS
ECHO.
ECHO Copying /root from Server2...please wait
ECHO.
XCOPY \\Server2\root /S F:\Backup\serverbackup\Server2\root
ECHO.
ECHO /root successfully transfered
ECHO.
choice /c:y /t:y,4 /n
CLS
ECHO.
choice /c:y /t:y,4 /n
ECHO ********************************************************
ECHO.
ECHO BATCH PROCESS COMPLETED SUCCESSFULLY
ECHO.
rem choice /c:y /t:y,3 /n
CLS
ECHO.BATCH PROCESS COMPLETED SUCCESSFULLY >TIME.LOG
ECHO.
ECHO. |TIME > TIME.LOG
ECHO.
ECHO. |DATE >> TIME.LOG
ECHO.
EXIT



Edit this as you see fit.

Now go to Start - Programs - Accessories - System Tools - Scheduled Tasks

Add a schedueled task to run every day at 3:30am (or whenever you feel is the best time). Make it run as a diffrent user (Guest).

And there you go!

Please note that you could do the opposite if you chose to... backup files from windows to linux. I'll make a short turorial for that later.