-   Linux - General (
-   -   Linux-to-Linux smb copy (cron job)? (

bardanes 10-14-2005 12:15 AM

Linux-to-Linux smb copy (cron job)?

Somewhat noob here.

I have a Debian Sarge Samba server and I want to backup files to a Buffalo LinkStation, which I have ordered. I don't know much about the Buffalo, but Buffalo tech support states that it runs a Linux kernel. Tech support knows nothing about accessing the Linkstation from Linux. I'm assuming that I can access the Linkstation by using smbmount with the appropriate user name and password in the following manner:

# mount -t smbfs -o username=name,password=pass //buffaloname/share /mountpnt/share

I want to set up a cron job to perform the backup described previously. I only want the Linkstation to be accessible when the cron job runs to do the copy.

Would the best approach be to write a script with something like:

#!/bin/sh -e
# cron copy script
mount -t smbfs -o username=name,password=pass //buffaloname/share /mountpnt/dest
cp -R sourcedir/* /mountpnt/dest
umount /mountpnt/dest

Is there a Samba/smb command that will combine the mount and copy? And is there a way that I can avoid having to put the password in the mount command?


jschiwal 10-14-2005 01:42 AM

Read the man pages for mount and smb
passwd program = /usr/bin/passwd %umount. There is a "credentials=<filename>" option.

specifies a file that contains a username and/or password. The
format of the file is:

username = <value>
password = <value>
Make sure that only root can read the credentials file.

You might want to use the "find" command to return the names of files changed after the last backup. That way, you won't be rewriting the same files over and over, and hopefully save time. Also, you may want to use the return value
of the mount command before attempting to perform the backup. Suppose the mount fails and you proceed to write to /mountpnt/dest. This will write files to the mount point directory instead of to the share. If there is an error mounting the share, you can log a message based on the return value. The man pages lists them:

mount has the following return codes (the bits can be ORed):

0 success
1 incorrect invocation or permissions
2 system error (out of memory, cannot fork, no more loop devices)
4 internal mount bug or missing nfs support in mount
8 user interrupt
16 problems writing or locking /etc/mtab
32 mount failure
64 some mount succeeded

JDaniels 10-14-2005 01:32 PM

rsync would work well. It only transfers updates, and it can transfer over different hosts. An example would be:


rsync -vaz /path/to/dir/ host:/path/to/dir
This would transfer files from /path/to/dir on the local machine, to /path/to/dir on host.

bardanes 10-17-2005 01:08 PM

Thanks for the quick replies! I really appreciate the help!

I got the Buffalo and set up the copy script. rsync is great, but I couldn't use rsync because I couldn't open port 22 or install software on the Buffalo system partition without root privileges. I haven't found a way to hack into root on the Buffalo yet, but I'm still playing with it. So,

The initial script starts out like this facsimile (will be changed to use a case statement). I'm going to move the user/password information to an encrpyted file shortly.

#!/bin/sh -e
# Basic Buffalo link copy
DATER=`date +%b%_3d%_9T`
# Mount the Buffalo drive
echo $DATER buffalocopy: starting procedure
if !(/bin/mount -t smb -o user=bozo,password=theclown //buffalosoldier/backemup /mnt/dest)
echo $DATER buffalocopy: mount failed: could not mount remote share
echo $DATER buffalocopy: terminated with error 1
exit 1

and so forth...any other comments or remarks? If not, thanks again!

archtoad6 10-17-2005 01:52 PM

Not familiar w/ the Buffalo, could you post a link?

jschiwal 10-17-2005 04:45 PM

Although the Buffalo device may be running Linux, don't assume that it is running on a 32bit x86 processor. Adding software to it might void your warranty also.

Consider looking at the manual for the tar command. This is the command that is usually used for making backups. Also, the manual for find (includes find, locate and xargs) could help you in writing a cron script that performs selective incremental backups.

You may need to go to the source to obtain the manuals. The source files that are used to produce the info files can also produce pdf/dvi/ps versions of the manuals. Running "./configure && make pdf" in the source directory will produce the manuals. These are targets in the generated Makefile that are not run by default.

All times are GMT -5. The time now is 05:34 PM.