Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 6th April 2010, 15:32
savin savin is offline
Junior Member
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Auto copy folders from ubuntu server to windows and vice versa

Hi can any one help me in this... Many Thanks in advance...



1. I need a script(like a scheduled cron job) which should perform Automatic copy (backup) of a directory from ubuntu server to windows and vice versa....


i tried every thing like samba mounting,ftp,etc..
with samba its possible to map the network drive of an ubuntu directory in windows..
but if the ubuntu server is not available then i cant access the network share..

Exactly this situation is happening for me while backing up tmp directory of ubuntu server ...

so in this case i need a permanent backup of tmp directory of ubuntu server in windows rather than a network share.



2. Also any ideas or scripts regarding automatic ftp (while doing a backup) from ubuntu server to windows... which can easily solve the above issue...
Reply With Quote
Sponsored Links
  #2  
Old 9th April 2010, 13:21
zetnsh zetnsh is offline
Senior Member
 
Join Date: Aug 2007
Posts: 111
Thanks: 8
Thanked 5 Times in 5 Posts
Default

Just a thought, but had you considered installing Cygwin on the windows machine (See http://www.cygwin.com/) which will allow you to use scp or rsync to copy between your machines?

So long as Cygwin is running on windows, then you should be able to drive everything from a crontab on the Ubuntu box. Would that work? Personally I find rsync an invaluable tool for backing stuff up.

Worth a shot anyway! If you reckon you can get that up and running, I can give you a hand with the syntax for rsync

Neil
Reply With Quote
  #3  
Old 9th April 2010, 13:26
savin savin is offline
Junior Member
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks bro for tis response...
i need rsync configurations...
Reply With Quote
  #4  
Old 10th April 2010, 09:55
zetnsh zetnsh is offline
Senior Member
 
Join Date: Aug 2007
Posts: 111
Thanks: 8
Thanked 5 Times in 5 Posts
Default

OK... <takes deep breath>... I've just tried this and made a few notes! It's not perfect though!

1. Install cygwin on your windows PC, following through the setup wizard, which you can get from here:
- when prompted by the installer, select Install from internet, accept the default settings
- when prompted for a local package directory, enter something like c:\packages
- choose a suitable mirror geographically near you
- At the select packages screen, select the following to install
Net -> openssh
Net -> rsync

Then click Next and follow through the rest of the setup

2. Configure cygwin's openssh server as follows:
- Start a bash shell from the windows machine. This is found under Start Menu -> Programs -> Cygwin -> Cygwin Bash Shell.
Under Vista/W7 You MUST right click on this and select Run as Administrator from the menu
- run
Code:
ssh-host-config
and answer questions as follows:

Should privilege separation be used? no (yes may be more secure, but might give problems if you want free reign to back up stuff)
Do you want to install sshd as a service? yes
Enter the value of CYGWIN for the daemon: ntsec
Do you want to use a different name? no
Create new privileged user account 'cyg_server'? yes
Please enter the password: <your choice>
Reenter: <same choice>

- run:
Code:
net start sshd
3. You will probably also need configure the windows firewall to allow SSH connections.
In Vista, you can start the Firewall configuration by searching for Firewall in the start menu. You want "Windows Firewall Settings".

On the Exceptions tab, click on "Add Port", enter "SSHD" as the name, and 22 as the port number. The protocol is TCP. Then click OK

Personally, I'm more a Linux man than a Windows man, so I'm a little hazy on Windows permissions, so you might have to fiddle a little with windows user accounts to get things to work properly for your backup.

4. Set up public key authentication between the 2 boxes.
The idea here is that both machines can log in to each other without a password. If you need help with this aspect, just let me know. But basically, it's like this:

a. On the Linux box, as the user from which you will be performing the rsync (ie the user which pulls data from the windows box):
Code:
ssh-keygen -t rsa
(accept the defaults, blank passphrase)
b. Get the public key, and copy it to the clipboard:
Code:
cat ~/.ssh/id_rsa.pub
(then copy the resulting text to the clipboard)
c. On the Windows box, logged in as the user you will be pulling data from, start a Cygwin bash session
d. Create the directory .ssh and change to it:
Code:
mkdir .ssh
		cd .ssh
e. Create a file "authorized_keys", by using echo, as no other editor is probably installed:
Code:
echo "<paste public key here>" >> authorized_keys
or if that's complicated, just do
Code:
notepad authorized_keys
and paste in there
f. From the Linux machine, test you can log in without a password. This is essential for unattended backups.
Code:
ssh <IP address of Windows Machine> -l <username on windows machine>
The first time you will get a message warning you that the authenticity of the new host can't be established.
This is perfectly normal, you'll only see this once. Say "yes".



5. Perform an rsync
Now you are ready to try an rsync!

For this step, bear in mind that the local PC c: drive is accessible from within the Cygwin bash shell as /cygdrive/c/

So the syntax goes something like this, this example is run from the Linux machine (replce with your own details):

rsync -az neil@10.43.0.50:/cygdrive/c/Users/neil/ backups/

On my setup, this will back up the whole of my User directory to the backups/ directory on my linux box

When you have this command working as you want, you can then automate it via cron.

This also works the other way round of course, from the Linux box to the windows box.
You would just have to sort out public key authentication the other way round, and then reverse the last 2 parameters of rsync

I hope that helps you, sorry it's not perfect, but hopefully it will get you started.

Good luck!

Neil
Reply With Quote
  #5  
Old 12th April 2010, 12:55
savin savin is offline
Junior Member
 
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default Thanks Bro

Let me try tis...
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu 7.10 and Windows password/user sync? ovredsson Server Operation 0 12th May 2008 21:26


All times are GMT +2. The time now is 20:19.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.