# ZFS panic



## xy16644 (Aug 6, 2012)

Last night I created an executable file in /root called "zfsbackup". The contents of this file was as follows:

```
#!/bin/sh
zfs snapshot -r bootdir@`date +%d.%m.%Y`-bootdir
zfs send -Rv bootdir@`date +%d.%m.%Y`-bootdir | gzip > /backups/bootdir/`date +%d.%m.%Y`-bootdir.zfs.gz
zfs destroy -r bootdir@`date +%d.%m.%Y`-bootdir
zfs snapshot -r zroot@`date +%d.%m.%Y`-zroot
zfs send -Rv zroot@`date +%d.%m.%Y`-zroot | gzip > /backups/zroot/`date +%d.%m.%Y`-zroot.zfs.gz
zfs destroy -r zroot@`date +%d.%m.%Y`-zroot
cd /backups; find . -type f -mtime +60d -delete;
```

When running this file manually all was fine. When running it via cron manually it was fine. But when it ran as scheduled early this morning it caused my server to crash (panic?) and I had to reboot. 

Questions:

1) How can I see the errors that were on the console screen this morning so I can troubleshoot? 

2) Why is this backup script causing the server to crash?

I'm running FreeBSD 9.0 RELEASE i386 with 4GB RAM.

My /boot/loader.conf has the following ZFS options set:

```
vfs.zfs.prefetch_disable="1"
vfs.root.mountfrom="zfs:zroot"
zfs_load="YES"
vm.kmem_size="512M"
vm.kmem_size_max="512M"
```

All my ZFS pool are encrypted with GELI except /boot.


----------



## da1 (Aug 6, 2012)

1) Check /var/log/all.log (if you have it enabled - if not, enable it and reproduce the problem).
2) That should be visible in the logs. Also, you can enable kernel dumps.

As a side note, it might be a good idea to check if the script is already running before executing the [cmd=""]zfs send[/cmd] command. You can also set the script to run in verbose mode [cmd=""]set -x[/cmd] and let it run via cron (hopefully it will produce some useful info).


----------



## kpa (Aug 6, 2012)

Try setting the vfs.zfs.arc_max /boot/loader.conf tunable to a reasonably low number, like 384MB:


```
vfs.zfs.arc_max="384M"
```

Even if you have 4GBs of memory the ARC cache can use only a small portion of it on i386 because it's limited by the maximum size of the kernel memory map that is 512MBs with GENERIC kernel.

Amd64 version of FreeBSD doesn't suffer from the same limitations, you can use much more memory for ARC cache on amd64.


----------



## xy16644 (Aug 6, 2012)

Thank you for the replies. Currently I'm stuck on i386 until I can find the time (and hardware!) to move to amd64.

I think I need to start by tweaking by loader.conf for an i386 system and ARC cache is a good starting point so thanks for recommending that.

This is going to sound like a noob question but here it goes anyway. When creating a script (in this case for backups) is it just a matter of creating an empty file and starting the file off with the value *#!/bin/sh*? After that I give the file execute rights in the /root directory and (for now) I use Webmin to schedule the job in cron to run as root. Is this an ok approach? How does one schedule this in cron via the command line (and test it)? 

Is it possible to have an email sent to me once my backup script has run with the output in it saying whether is was successful or not? Should this be included in the script file?


----------



## Sebulon (Aug 7, 2012)

@ xy16644

Maybe you would be interested in a tool I have written that simplifies the procedure?

replicate - Initial and continous ZFS filesystems replication

/Sebulon


----------

