# 8.1 mksnap_ffs: Cannot create snapshot //.snap/dump_snapshot: ?



## da1 (Sep 30, 2010)

Hello fellas,

on a 8.1-release i386 I have the following in crontab:

```
*/10   *       *       *       *       root    /root/scripts/util/connection_check
*/10    *       *       *       *       root    /root/scripts/util/ftpguard.sh /var/log/messages &> /dev/null
15      3       *       *       *       root    /usr/local/bin/cvsup -g -L 2 -h `/usr/local/bin/fastest_cvsup -q -c tld` /root/cvsup/ports-supfile
[B]*       2       *       *       *       root    /root/scripts/util/backup_plan.sh[/B]
```

The last one, backup_plan.sh, is failing miserably in 80% of times.

The script looks like this:

```
################ Variables #################
fs="/dev/mirror/gm0s1a"                         # Set which FS's to be backed up
                                                # full path
fs2=gm0s1a                                      # Set to ONLY name of slice/partition itself
                                                # do not set full path here
target_dir="/mnt/date/backups"                  # Target dir
filename="$fs2.`/bin/date +%a.%d.%m.%Y`"        # File name format
fstab="/etc/fstab"
fstab_copy="fstab"


############### Executables ################
today=`date +%a`
date=`/bin/date`
dump="/sbin/dump"
find="/usr/bin/find"
rm="/bin/rm"
cp="/bin/cp"
swapinfo="/usr/sbin/swapinfo"

########### !!! MAINTENANCE !!! ############
# Delete all backups older than 30 days
$find $target_dir -mtime +30d -exec $rm -rf {} \;

# Move fstab to $target_dir to have a copy
# & insert swapinfo data
$cp /etc/fstab $target_dir
echo "" >> $target_dir/$fstab_copy
$swapinfo >> $target_dir/$fstab_copy


for i in $fs;
do
case $today in
      Sun) $dump -0Lauf $target_dir/$filename.L0.dump $fs;;
      Mon) $dump -1Lauf $target_dir/$filename.L1.dump $fs;;
      Tue) $dump -2Lauf $target_dir/$filename.L2.dump $fs;;
      Wed) $dump -3Lauf $target_dir/$filename.L3.dump $fs;;
      Thu) $dump -4Lauf $target_dir/$filename.L4.dump $fs;;
      Fri) $dump -5Lauf $target_dir/$filename.L5.dump $fs;;
      Sat) $dump -6Lauf $target_dir/$filename.L6.dump $fs;;
      *) echo "Unknown day of week. Exiting ...";;
esac
done
```

It may not be the best script and it may not be written in the best way, but when I run it manually it works.
When crontab runs it however it fails with:

```
mksnap_ffs: Cannot create snapshot //.snap/dump_snapshot: ?(: Device busy
dump: Cannot create //.snap/dump_snapshot: No such file or directory
```
 and it keeps at it for ~1h (in which time the root mailbox get's ~60-80 e-mails about this error)

At the time the backup script runs, there is pretty much no activity on the server.
It occurred to me that open files may be a problem but as far as I know that's what the "-L" dump option is for (for mounted FS's). Ow, the FS specified in the script is the "/" partition.


Can anyone give me a hint here ?




LE:

I realize that "/.snap/dump_snapshot" doesn't exist, but this is not a problem when I run the script manually. The weir thing is that even when the file was there, the crontab script was failing.


----------



## graudeejs (Sep 30, 2010)

perhaps it's extra */* then script is running automatically

Also note, that UFS snapshots have Max limit of 20 snapshots


----------



## da1 (Sep 30, 2010)

killasmurf86 said:
			
		

> perhaps it's extra */* then script is running automatically



Aahh, I'm sorry, I don't think I follow .....



> Also note, that UFS snapshots have Max limit of 20 snapshots


So, you make 20 snapshots and that's it ? 
No, it cannot be .... maybe there is something wrong this morning with me because I don't think I follow this one either.

Please be so kind and elaborate


----------



## graudeejs (Sep 30, 2010)

ufs is limited to 20 snapshots at any time per UFS filesystem....
If you want new snapshots, you have to delete some old ones

if you want more than 20 snapshots, use zfs


----------



## Galactic_Dominator (Sep 30, 2010)

Perhaps sysutils/freebsd-snapshot would be better than reinventing the wheel.


----------



## graudeejs (Sep 30, 2010)

```
mksnap_ffs: Cannot create snapshot [red]/[/red]/.snap/dump_snapshot: ?(: Device busy
```


----------



## da1 (Sep 30, 2010)

killasmurf86 said:
			
		

> ```
> mksnap_ffs: Cannot create snapshot [red]/[/red]/.snap/dump_snapshot: ?(: Device busy
> ```



ahaa .. I see it.

thx, I'll look into that .... but still, it's weird it only fails when ran from crontab


----------



## DutchDaemon (Sep 30, 2010)

Crontab uses /bin/sh, you may not. The script doesn't have a #!shell defined at the beginning, so maybe there's something 'shell-specific' in your script that causes it to fail when run from cron? Just a guess. Maybe switch from backticks to more modern syntax as well.


```
date=`/bin/date`
date=$(/bin/date)
```


----------



## da1 (Sep 30, 2010)

the script has

```
#!/bin/sh
```
typo error there. srry


----------



## da1 (Sep 30, 2010)

UPDATE:

I commented out the following line:

```
# Delete the temp snapshot
$rm -f /.snap/dump_snapshot
```
and set the crontab to run 1 min after the modification. basically, it worked.

I've set the crontab job back to it's original hour and I will see tomorrow.

*@killasmurf86:* atm, I have only 5 snapshot's in the "target_dir". This shouldn't be a problem if you say, 20 is the limit.
I also tried ZFS about 3 weeks ago but I couldn't get a higher than 20MB/sec write speed, so off it went and in came ufs (again).


----------



## da1 (Oct 1, 2010)

So, last night the script ran without any error.

Another change I did was modify the minutes in crontab from "*" to "1". This way, the script is started only one time, whereas with "*" the script was started every other minute and I'm guessing that was the cause for the "resource unavailable" error msg.


----------

