Script to copy User home folders to mounted windows share

First of all, let me state that I am a windows admin.

I have a windows share mounted to /mnt/server

I need a script that will either login as sudo or perform commands with sudo rights. I need the script to copy all of the users /home folders to the mounted windows share. Now If I can schedule this script somehow, I will need the script to either, only copy the changes or overwrite the old folder each time the script is run.

I am using Fedora 10. THe type os script does not matter to me, but I do know the server runs bash.

I could create this script easily within windows, but since I need to involve linux, I am not comfortable with the syntax of linux scripts.

Thank you in advance for any help.
Eric

There are man pages on rsync which automates this sort of thing, cp and cpio -p. If the volume is small, and no versioning/save newest is desired, you can just cp:

cd /home
cp -rp * /mnt/server

One issue is how to handle links and symbolic links -- some tools can move the links, other make copies of the target files or subtrees. Another idea is to zip each user's data over to there. Not only is there less space used, less data flows over the net and there is less delay creating and traversing remote directories. Windows can traverse the zip like a dir., lately!

I did a:

Sudo CP -r /home/* /mnt/share

this seems to be working. How easy is it to make a script from this command?

Also I see there is a -u switch to copy only changed or new files..would that be:

sudo CP -u -r /home/* /mnt/share

There are many different variations on cp. I would use the u, and the p. You could even do each user in parallel, for some speedup. How many users, how much data?

What I am doing is making a bit for bit copy of the users Maildir folders to a windows share so that I can get those folders backed up onto the nightly tape.

there is maybe 40 users and I am thinking 100GB or so, I will be able to tell you better on the size after this first copy is done.

If you have 100G more or less you should use rsync, much more faster then cp, and with the stats option you can see if there was something that he didn't copy.

try something like this :

rsync --verbose --relative --recursive --update --delete --perms --owner --group \
--times --links --safe-links --super --compress --one-file-system --devices $source $dest

Ok, the copy finished and the main issue I see is that all of the files in each users Maildir folder are 0kb, so I think that these are links and the actual email files are stored elsewhere (not sure where).

Some of the tools can discover hard and soft links and move them as such, or make copies, at your option: rsync, cpio pass mode link options and a similar option in newer cp's. Do not hide from the man pages!

Try running the following to see what changed. (\t should be a real tab, must use ksh on a machine with /dev/fd/ or bash)

comm -3 <(  
  cd /home
  find . | xargs -n99 ls -ld | sort
 ) <(
  cd /mnt/server
  find . | xargs -n99 ls -ld | sort
 ) | sed '
  s/^\t/mnt:  /
  t
  s/^/home: /
 ' >/tmp/copy_comm.txt
 
or:
 
diff <(  
  cd /home
  find . | sort | xargs -n99 ls -ld
 ) <(
  cd /mnt/server
  find . | sort | xargs -n99 ls -ld
 ) >/tmp/copy_diffs.txt