copy a folder under linux server to windows server

6,370

Solution 1

MS-Windows shared folder: You can share data between windows and linux system for such use : For example you would like to access MS-Windows share called //windowsserver/sharename by mounting to /mnt/win directory under Linux system. So execute these commands:


mkdir -p /mnt/win
mount -t smbfs -o username=winntuser,password=mypassword //windowsserver/sharename /mnt/win
Next create the password file /etc/sambapasswords:

cat > /etc/sambapasswords 
username = winntuser
password = mypassword
make sure that only root have access to it

chown root:root /etc/sambapasswords
chmod 600 /etc/sambapasswords
Add an entry to your /etc/fstab:

//windowserver/share /mnt/win smbfs
auto,gid=users,fmask=0664,dmask=0775,iocharset=iso8859-15, credentials=/etc/sambapasswords 0 0
Append an entry to your crontab like this, if you need to do a backup daily at 1AM:

0 1 * * * cp /path/to/yourbackup /mnt/win 
FTP solution: you may install a ftp server on your windows machine. filezilla server do perfectly the job. setup a ftp folder and an account with all required privileges. Later setup a file named ~/.netrc with this content:

machine windowserver
login ftpuser
password ftppassword
make sure that only root have access to it:

chown root:root ~/.netrc
chmod 600 ~/.netrc
Append to your backup script this lines that will transfer your backup file remotely to your ftp server:

#!/bin/bash
filename=yourbackupfile
ftp <<EOF
open windowserver
bin
verbose
prompt
cd ${remote_path}
put ${filename}
bye
EOF
Finally add your backup script to your crontab like what we did for first solution.

Solution 2

You can also do this with rsync. Set up a rsync server at the Linux machine, and use a rsync client at the Windows machine to get the files.

With rsync, you will be able to resume interrupted transfers

Solution 3

Another way will be to actually pull the needed files away from the Linux server from the Windows server, using pscp (from the putty package)

Solution 4

Here is my script in order to communicate with our windowser server. You need to add a share (ie Samba share) on the windows box :

#!/bin/sh
# Script d'envoi des archives 

cd /mount directory
mount -t cifs //SMB-SHARE share name/ -o username=USER,password=PASSWORD,dir_mode=0777,file_mode=0777

umount share
Share:
6,370

Related videos on Youtube

Dennis Williamson
Author by

Dennis Williamson

Stackathlon Leader Boards #SOreadytohelp The Bridge Builder             I am the first user         to earn at least 50,000         reputation points each                                  on all three of               Stack Overflow,              Server Fault and                  Super User.   I was also the first user to surpass   the 10K, 20K, 30K and 40K point levels each on all three of those sites. ###Are you a Stackathlete? ###Check the standings on Profile:I'm a Unix/Linux devops engineer/sysadmin/programmer Devotion to Duty Try my unofficial Printifier for xkcd.

Updated on September 17, 2022

Comments

  • Dennis Williamson
    Dennis Williamson over 1 year

    I need to find a way to transfer the daily backup folder of my Debian server to a Windows server weekly. What would be the easiest and most stable way to achieve this? Would I definitely need a Samba installation on my Debian server?

  • Keith Stokes
    Keith Stokes over 14 years
    I do almost exactly the same thing as Kronick describes for an hourly copy from a Linux to a Windows machine.
  • Dave Drager
    Dave Drager over 14 years
    This is the best, most easy, and most stable way to do this. No servers to set up - just make sure the samba client is installed on the Linux machine, which is probably already is.
  • Clay Kimber
    Clay Kimber over 14 years
    And like Nik says above, if you use key authentication, you can script it.