# RSync Operation Timeout



## aceman (Oct 6, 2012)

I set up an rsync with cron to backup files on a freebsd 8.0

using below code:

```
SRCDIR="/home/users"
BACKUPDIR="/mnt/BACKUP"
LOGERRFILE="/<some_path>/file_users_logERR.txt"
LOGOKFILE="/<some_path>/file_users_logOK.txt"

if [ ! -d "$BACKUPLOC" ]; then
        mount_smbfs -I <ip_address> -L en_US.ISO8859-1 -W Workgroup -N //guest@<ip_address>/Volume_1/ /mnt/BACKUP
fi

echo "" > "$LOGERRFILE"


/usr/local/bin/rsync -avzh --progress --iconv=UTF-8,ISO8859-1  "$SRCDIR"  "$BACKUPDIR"  2> "$LOGERRFILE" > "$LOGOKFILE"

if [ -s "$LOGERRFILE" ]; then

   //send email
   exit 1
fi
```

But there is a problem when I scheduled it using Cron Jobs in the Freebsd

```
rsync: mkstemp ... failed: Operation timed out (60)
rsync: recv_generator: .... class": Operation timed out (60
```

The /mnt/BACKUP is a mounted Network Storage(NAS)

Please advise


----------



## mamalos (Oct 6, 2012)

Does your script work when you run it yourself (not in a cron job)?


----------



## aceman (Oct 7, 2012)

Yes it is , working without any timeout


----------



## wblock@ (Oct 7, 2012)

The script should test to see if mount_smbfs(8) succeeds.  But instead use mount -t smbfs, and use full paths to commands.


----------



## aceman (Oct 8, 2012)

mount_smbfs works without any errors, let me try using /usr/sbin/mount_smbfs


----------



## aceman (Oct 8, 2012)

mount -t smbfs is not working, but /usr/sbin/mount_smbfs is working fine.

The whole script is running smoothly if I run in manually


----------



## mamalos (Oct 8, 2012)

Try this on your first two lines of your script:

```
SET IFS='
'
```
and see if it runs. If not, explain how you run it via CRON.


----------



## aceman (Oct 9, 2012)

I saved the script on a file /home/script/backup.sh.


```
#!/bin/bash

SRCDIR="/home/users"
BACKUPDIR="/mnt/BACKUP"
LOGERRFILE="/<some_path>/file_users_logERR.txt"
LOGOKFILE="/<some_path>/file_users_logOK.txt"

if [ ! -d "$BACKUPLOC" ]; then
        mount_smbfs -I <ip_address> -L en_US.ISO8859-1 -W Workgroup -N //guest@<ip_address>/Volume_1/ /mnt/BACKUP
fi

echo "" > "$LOGERRFILE"


/usr/local/bin/rsync -avzh --progress --iconv=UTF-8,ISO8859-1  "$SRCDIR"  "$BACKUPDIR"  2> "$LOGERRFILE" > "$LOGOKFILE"

if [ -s "$LOGERRFILE" ]; then

   //send email
   exit 1
fi
```

Then I configure using crontab -e


```
0 6 * * * /home/script/backup.sh
```


----------



## aceman (Oct 9, 2012)

please give more details for

```
SET IFS='
'
```


----------



## mamalos (Oct 9, 2012)

IFS is the Internal Field Separator. For more info you can read this. The thing is that it is not uncommon for shell programs to behave "unexpected" and the strange behaviours vanish once the IFS is set properly. So, my suggestion is to set it as the new line character. Have you tried it? Did it work?

Secondly: as what user are you running the cron script? root I suppose?


----------



## aceman (Oct 9, 2012)

For the IFS I got an error
 SET: command not found

yes, I run the cron as root


----------



## wblock@ (Oct 9, 2012)

I don't see where IFS would be a problem here.

1. As said above, it is important to test that the mount succeeds.  It could fail for any number of reasons, and the script will fail.  Possibly just like it does.
2. Don't use bash.
3. BACKUPLOC is is not defined.  BACKUPDIR is used in the rsync command.


----------



## aceman (Oct 10, 2012)

1. The mount is working fine

2. Please advise what should I use, sh: 

```
#!/bin/sh
```

3.Sorry for the wrong code

```
if [ ! -d "$BACKUPDIR" ]; then
```


----------



## wblock@ (Oct 10, 2012)

aceman said:
			
		

> 1. The mount is working fine



Disconnect a network cable, or turn off the NAS, change permissions, or use a different environment.  These will all cause the script to fail.  That's why it should test for success.

The test to see if BACKUPDIR is a directory is not useful.  To be a mountpoint, it is already a directory.  A better test would be to see if BACKUPDIR contains a known file that is in the mounted directory but not in the empty mountpoint.



> 2. Please advise what should I use, sh:
> 
> ```
> #!/bin/sh
> ```



Yes.


----------



## mamalos (Oct 11, 2012)

aceman said:
			
		

> For the IFS I got an error
> SET: command not found



My mistake, I meant: set:

```
IFS='
'
```


----------

